使用 WWW::Mechanize::TreeBuilder 时出现错误消息“无法定位对象方法“get_ok””的原因是什么?
我真的不知道如何使用 WWW::Mechanize::TreeBuilder 。基本上我使用 WWW::Mechanize 获得一个 HTML 页面。我想提取一个 //div[@class='cars']
其文本。
我试过:
my $mech = WWW::Mechanize->new();
$mech->get('the url');
WWW::Mechanize::TreeBuilder->meta->apply($mech);
$mech->get_ok('//div[@class="cars"]');
print $mech->look_down(_tag => 'p')->as_trimmed_text . "\n";
它说:
Can't locate object method "get_ok" via package "Class::MOP::Class::__ANON__::SERIAL::2" at orpi_crawler.pl
I couldn't really figure out how to use WWW::Mechanize::TreeBuilder. Basically I get a HTML page using WWW::Mechanize. There is a //div[@class='cars']
whose text I want to extract.
I tried:
my $mech = WWW::Mechanize->new();
$mech->get('the url');
WWW::Mechanize::TreeBuilder->meta->apply($mech);
$mech->get_ok('//div[@class="cars"]');
print $mech->look_down(_tag => 'p')->as_trimmed_text . "\n";
It says:
Can't locate object method "get_ok" via package "Class::MOP::Class::__ANON__::SERIAL::2" at orpi_crawler.pl
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
get_ok
来自您忽略加载的Test::WWW::Mechanize
。仔细阅读WWW::Mechanize::TreeBuilder
的概要。get_ok
is fromTest::WWW::Mechanize
which you neglected to load. Read the synopsis ofWWW::Mechanize::TreeBuilder
carefully.