1

使用している Perl コードが機能しHTML::TableExtractません。

これが私のコードです

#!/usr/bin/perl
use strict;
use warnings;

use HTML::TableExtract;


## Exactract table from html file
my $te = new HTML::TableExtract( attribs => { border => 0} );
$te->parse_file("file_path.html");
my $table = $te->tables;

for my $row ($table->rows) {
    print join(',', @$row), "\n";
}

このエラーが発生し続けます

Can't call method "rows" without a package or object reference at ./parse_table.pl line 13.

これが私のHTMLファイルで、興味のあるテーブルだけを表示するために切り詰められています。 http://phucnvo.myvnc.com/sandbox/out.html

<div>
  <form name="listAssignmentsForm" action="https://t-square.gatech.edu/portal/tool/3a34f619-99d1-4548-be57-9ee977fd8127?panel=Main"
    method="post">
    <input type="hidden" name="source" value="0"/>
    <table class="listHier lines nolines" border="0" cellspacing="0"
      summary="List of assignments. Column headers are also links which can be used to sort the table by that column. Column 1: Indicates if the assignment has attachments. Column 2: assignment title and links to edit, duplicate or grade(if allowed). Column 3: status. Column 4: opening date. Column 5: due date. The rest of the columns may or may not be present. Column 6: may have the number submitted and graded. Column 7: may have checkboxes to select and remove the assignment.">
      <tr>
        <th id="attachments" class="attach"> &nbsp; </th>
        <th id="title">
          <a href="#" onclick="location='url'; return false;" title="Sort by title"> Assignment title </a>
        </th>
        <th id="For">
          <a href="#" onclick="location='url'; return false;" title="Sort by audience">For</a>
        </th>
        <th id="status">
          <a href="#"
            onclick="location='https://t-square.gatech.edu/portal/tool/3a34f619-99d1-4548-be57-9ee977fd8127?criteria=assignment_status&amp;panel=Main&amp;sakai_action=doSort'; return false;"
            title="Sort by status"> Status </a>
        </th>
        <th id="openDate">
          <a href="#"
            onclick="location='https://t-square.gatech.edu/portal/tool/3a34f619-99d1-4548-be57-9ee977fd8127?criteria=opendate&amp;panel=Main&amp;sakai_action=doSort'; return false;"
            title="Sort by section"> Open </a>
        </th>
        <th id="dueDate">
          <a href="#"
            onclick="location='https://t-square.gatech.edu/portal/tool/3a34f619-99d1-4548-be57-9ee977fd8127?criteria=duedate&amp;panel=Main&amp;sakai_action=doSort'; return false;"
            title="Sort by due date"> Due </a>
        </th>
      </tr>
      <tr>
        <td headers="attachments" class="attach">
          <img id="attachment1" src="/library/image/sakai/attachments.gif?panel=Main" alt="Attachments" width="13" height="11" border="0"/>
        </td>
        <td headers="title">
          <h4><a href="url">Project 7</a></h4>
        </td>
        <td style="padding-bottom:0"> site </td>
        <td headers="status"> Submitted Jul 24, 2013 12:24 am </td>
        <td headers="openDate"> Jul 19, 2013 12:00 pm </td>
        <td headers="dueDate"> Jul 26, 2013 11:55 pm </td>
      </tr>
      <tr>
        <td headers="attachments" class="attach">
          <img id="attachment2" src="/library/image/sakai/attachments.gif?panel=Main" alt="Attachments" width="13" height="11" border="0"/>
        </td>
        <td headers="title">
          <h4><a href="url">Project 6</a></h4>
        </td>
        <td style="padding-bottom:0"> site </td>
        <td headers="status"> Submitted Jul 19, 2013 4:33 am </td>
        <td headers="openDate"> Jul 11, 2013 12:00 pm </td>
        <td headers="dueDate"> Jul 18, 2013 11:55 pm </td>
      </tr>
      <tr>
        <td headers="attachments" class="attach">
          <img id="attachment3" src="/library/image/sakai/attachments.gif?panel=Main" alt="Attachments" width="13" height="11" border="0"/>
        </td>
        <td headers="title">
          <h4><a href="url">Project 5</a></h4>
        </td>
        <td style="padding-bottom:0"> site </td>
        <td headers="status"> Submitted Jul 10, 2013 11:37 pm </td>
        <td headers="openDate"> Jun 27, 2013 12:00 pm </td>
        <td headers="dueDate"> Jul 10, 2013 11:55 pm </td>
      </tr>
      <tr>
        <td headers="attachments" class="attach">
          <img id="attachment4" src="/library/image/sakai/attachments.gif?panel=Main" alt="Attachments" width="13" height="11" border="0"/>
        </td>
        <td headers="title">
          <h4><a href="url">Threads Practice </a></h4>
        </td>
        <td style="padding-bottom:0"> site </td>
        <td headers="status"> Not Started </td>
        <td headers="openDate"> Jun 27, 2013 12:00 pm </td>
        <td headers="dueDate"> Jun 27, 2013 12:05 pm </td>
      </tr>
      <tr>
        <td headers="attachments" class="attach">
          <img id="attachment5" src="/library/image/sakai/attachments.gif?panel=Main" alt="Attachments" width="13" height="11" border="0"/>
        </td>
        <td headers="title">
          <h4><a href="url">Project 4</a></h4>
        </td>
        <td style="padding-bottom:0"> site </td>
        <td headers="status"> Submitted Jun 27, 2013 4:58 am </td>
        <td headers="openDate"> Jun 20, 2013 1:00 am </td>
        <td headers="dueDate"> Jun 26, 2013 11:55 pm </td>
      </tr>
      <tr>
        <td headers="attachments" class="attach">
          <img id="attachment6" src="/library/image/sakai/attachments.gif?panel=Main" alt="Attachments" width="13" height="11" border="0"/>
        </td>
        <td headers="title">
          <h4><a href="url">Project 3</a></h4>
        </td>
        <td style="padding-bottom:0"> site </td>
        <td headers="status"> Submitted Jun 20, 2013 3:19 am </td>
        <td headers="openDate"> Jun 6, 2013 12:00 pm </td>
        <td headers="dueDate"> Jun 19, 2013 11:55 pm </td>
      </tr>
      <tr>
        <td headers="attachments" class="attach">
          <img id="attachment7" src="/library/image/sakai/attachments.gif?panel=Main" alt="Attachments" width="13" height="11" border="0"/>
        </td>
        <td headers="title">
          <h4><a href="url">Project 2</a></h4>
        </td>
        <td style="padding-bottom:0"> site </td>
        <td headers="status"> Submitted Jun 5, 2013 5:39 am </td>
        <td headers="openDate"> May 28, 2013 12:00 pm </td>
        <td headers="dueDate"> Jun 4, 2013 11:55 pm </td>
      </tr>
      <tr>
        <td headers="attachments" class="attach">
          <img id="attachment8" src="/library/image/sakai/attachments.gif?panel=Main" alt="Attachments" width="13" height="11" border="0"/>
        </td>
        <td headers="title">
          <h4><a href="url">Project 1: Processor Design</a></h4>
        </td>
        <td style="padding-bottom:0"> site </td>
        <td headers="status"> Submitted May 31, 2013 2:09 am </td>
        <td headers="openDate"> May 16, 2013 1:40 pm </td>
        <td headers="dueDate"> May 30, 2013 11:55 pm </td>
      </tr>
    </table>
  </form>
</div>

私が期待しているのは、課題のタイトル、ステータス、開始日、終了日です。

4

2 に答える 2

3

ysthが示唆したように、あなたの問題はここにあります:

my $table = $te->tables;

tablesは複数形であり、リスト コンテキストで呼び出す必要があることを示しています。スカラーコンテキストで呼び出しています。Perl では、リストを返す多くの関数は、スカラー コンテキストで呼び出された場合、そのリストの長さを返します。 tablesはそのうちの 1 つなので、1$tableに設定されます。数値でメソッドを呼び出すことはできません (まあ、なしではできませんautobox)。

これを試して:

my ($table) = $te->tables;

代入の前のかっこは、それをリスト代入にします。$table最初に見つかったテーブルを取得し、それ以降のテーブルは破棄されます。

于 2013-10-02T06:52:44.930 に答える