简体   繁体   English

使用WWW :: Mechanize自动搜索

[英]Automatic Search Using WWW::Mechanize

I am trying to write a Perl script which will automatically key in search variables on this LexisNexis search page and retrieve the search results. 我正在尝试编写一个Perl脚本,该脚本将自动键入此LexisNexis搜索页面上的搜索变量并检索搜索结果。

I am using the WWW::Mechanize module but I am not sure how to figure out the field name of the search bar itself. 我正在使用WWW :: Mechanize模块,但我不知道如何找出搜索栏本身的字段名称。 This is the script I have so far -> 这是我到目前为止的剧本 - >

#!/usr/bin/perl
use strict;
use warnings;
use WWW::Mechanize;
my $m = WWW::Mechanize->new();

my $url = "http://www.lexisnexis.com/hottopics/lnacademic/?verb=sr&csi=379740";
$m->get($url);

$m->form_name('f');
$m->field('q', 'Test');
my $response = $m->submit();
print $response->content();

However, I think the "Name" of the search box in this website is not "q". 但是,我认为本网站搜索框的“名称”不是“q”。 I am getting the following Error - "Can't call method "value" on an undefined value at site/lib/WWW/Mechanize.pm line 1442." 我收到以下错误 - “无法调用方法”值“在站点/ lib / WWW / Mechanize.pm行1442上的未定义值。” Any help is much appreciated. 任何帮助深表感谢。 Thank you ! 谢谢 !

If you disable the JavaScript in your browser then you will notice that the search form doesn't load which means it's being loaded by JavaScript, that's why you are unable to handle it with WWW::Mechanize . 如果您在浏览器中禁用JavaScript,那么您会注意到搜索表单没有加载,这意味着它正在被JavaScript加载,这就是您无法使用WWW :: Mechanize处理它的原因。 Have a look at WWW::Mechanize::Firefox , this might help you with your task. 看看WWW :: Mechanize :: Firefox ,这可能会帮助您完成任务。 Check out the example scripts , cookbook and FAQs . 查看示例脚本cookbook常见问题解答

You can also do the same using Selenium, see Gabor's tutorial on Selenium . 你也可以使用Selenium做同样的事情,参见Gabor关于Selenium的教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM