0

使用下面的示例。我有一个使用Mojo::DOM解析的 HTML 文件。但是,我在其中一个页面中遇到了一个场景,其中有两个类,我需要读取两个类(问题和答案),其中包括一个标签及其需要填充的相应文本框。我在检索标签及其相应的文本框时遇到问题,以便我可以将正确的值填写到正确的框中。

<td class="Question">1</td>
<td class="Answer"><input type="text"/></td>
<td class="Question">2</td>
<td class="Answer"> <input type="text"/></input></td>
<td class="Question">3</td>
</td class="Answer"><input type="text"/></td>

请对我如何使用perl进行操作有任何想法?请注意,每个标签的内部文本会在每次脚本运行时发生变化。

4

1 回答 1

0

在摆弄 Mojo::Dom 之后,我能够选择标签的值,然后我将它与 WWW::Mechanize 结合起来,将其填充到输入文本框中。

my $url = "http://MyURL/Path"
my $mech  = WWW::Mechanize->new( agent => 'Mozilla/4.0 (compatible; MSIE 8.0; Windows 
NT 6.1)');
$mech->get($url);
$dom =  Mojo::DOM->new($mech->content);
my @temp =  $dom->find('.Question')->map(sub{$_->text})->each ;

它返回的数组按照我想要的顺序离开它。我从http://blogs.perl.org/users/joel_berger/2012/05/using-mojodom.html获得了参考,如果有人需要一个易于使用的工具,它确实很有帮助。

于 2012-08-30T12:55:44.237 回答