0

我想抓取使用 Javascript 或类似内容动态加载内容的网页。

类似于无头浏览器的东西,我可以在没有 X 的 Linux 共享主机上使用它。

我可以使用 PHP、Perl、Ruby 或 Python。

你们中有人知道一些可以帮助我的框架/无头浏览器吗?

非常感谢你。

4

3 回答 3

1

如果您需要模拟按键或单击以加载内容,请尝试使用Selenium来控制浏览器。

对于无头浏览器,这里列出了一些:无头互联网浏览器?

于 2012-07-20T15:19:36.633 回答
1

见图书馆WWW::Scripter

概要:

use WWW::Scripter;

$w = new WWW::Scripter;
$w->use_plugin('Javascript');
$w->get('http://some.site.com/that/uses/javascript');
$w->content; # returns the HTML content, possibly modified by scripts
$w->eval('alert("Hello from JavaScript")');
$w->document->getElementsByTagName('div')->[0]->...
于 2012-07-20T21:55:43.153 回答
-2

在 Perl 中使用 Perl WWW::Mechanize。该模块有许多方法可以执行类似 Web 浏览器的功能。下面是一个示例代码:

use WWW::Mechanize;
use strict;

my $username = "admin";
my $password = "welcome1";  
my $outpath  = "/home/data/output";
my $fromday = 7;
my $url  = "https://www.myreports.com/tax_report.php";
my $name = "tax_report";
my $outfile = "$outpath/$name.html";

my $mech = WWW::Mechanize->new(noproxy =>'0');  

$mech->get($url);
$mech->field(login => "$username");
$mech->field(passwd => "$password");

$mech->add_handler("request_send",  sub { shift->dump; return });
$mech->add_handler("response_done", sub { shift->dump; return });

$mech->click_button(value=>"Login now");

my $response = $mech->content();

print "Generating report: $name...\n";

open (OUT, ">>$outfile")|| die "Cannot create report file $outfile";
print OUT "$response";
close OUT;

如果您想处理网页中的 Javascript(您想要抓取),您可以查看WWW::Mechanize::Firefox,但这可能需要安装 Mozilla 的MozRepl插件。

于 2012-07-20T15:18:25.717 回答