0

我在编写一些代码时遇到问题。它基本上是我自己的概念证明,我将用它来运行单词以获得另一种形式(有趣的冰岛语共轭)。在代码中,我必须有一个 if 语句,以防单词本身的 URL 导致多个结果。从那里我找到相关链接,从那里获取内容并使用 TableExtract 来获取我需要的表格。除了我没有得到任何有用的东西。

#!perl



use warnings;
use HTML::TableExtract qw(tree);
use LWP::Simple;




sub saekja{
    $table = $te->first_table_found;
    $table_tree = $table->tree;
    $table_html = $table_tree->as_HTML;
};


sub leidretta{
#Ef að leitin skilar fleirri en einni niðurstöðu
    if ($content =~ /orð fundust./){

    $content =~ m/<li><strong><a href="(.*)">/;

#byrjunin á strengnum fyrir urlið
    $upphaf = "http://bin.arnastofnun.is/";
#skeytir saman strengjunum til að búa til urlið
    $urlid = $upphaf . $1;
    $content = get($urlid);
    $te  = new HTML::TableExtract( depth=>0, count=>0);



}
};
$content = get("http://bin.arnastofnun.is/leit.php?q=Fiskisl%C3%B3%C3%B0");

&leidretta;
&saekja;

我承认我在这方面相对较新(几乎正好一周前写了我的第一个 perl)。但我完全被难住了,大量的谷歌搜索没有发现任何有用的东西。

4

1 回答 1

1

这应该可以帮助您前进一点:

#!perl

use utf8;
use warnings;
use HTML::TableExtract qw(tree);
use LWP::Simple;

$content = get("http://bin.arnastofnun.is/leit.php?q=Fiskisl%C3%B3%C3%B0");

if ($content =~ /orð fundust./) {

    $content =~ m/<li><strong><a href="(.*)">/;

    $upphaf = "http://bin.arnastofnun.is/";
    $urlid = $upphaf . $1;
    $content = get($urlid);

    $te  = new HTML::TableExtract(depth=>0, count=>0);

    $te->parse($content);   # this was missing

    $table = $te->first_table_found;
    $table_tree = $table->tree;
    $table_html = $table_tree->as_HTML;

    print $table_html,"\n";
}

你基本上没有解析任何东西,所以HTML::TableExtract没有任何工作要做。我还需要添加use utf8到脚本中,以便正确处理非 ASCII 字符。

于 2011-05-25T19:51:13.297 回答