【问题标题】:Scraping JS contents of a site using perl使用 perl 抓取网站的 JS 内容
【发布时间】:2016-01-26 13:48:51
【问题描述】:

我正在废弃这个site 并正在寻找代码示例来帮助我弄清楚如何检索这个JSP 控件内部的信息(这比使用常规文本要困难得多!)。我似乎没有找到任何与 HTTP 标头有关的东西。到目前为止,这是我的代码:

 my $mech_r = new WWW::Mechanize();

 my $uri = 'http://global.krx.co.kr/contents/GLB/02/0203/0203000000/GLB0203000000.jsp';
 print "Getting '$uri'\n";
 my $page = $mech_r->get($uri);

 print "Parsing data...";
 my $root = HTML::TreeBuilder->new_from_content($mech_r->content());

 my ($news_table) = $root->look_down(
     sub {
         defined($_[0]->tag()) and
         $_[0]->tag() eq 'ul' and
         defined($_[0]->attr('class')) and
         $_[0]->attr('class') eq 'board-list'
     }
 );

 if (!defined($news_table)) {
     print Dumper($root);

     croak "Could not get the news table";
 }

我想获取标题、日期和链接。

但由于 javascript 正在加载,因此没有获取任何数据。

【问题讨论】:

    标签: javascript perl jsp mechanize


    【解决方案1】:

    如文档所述,WWW::Mechanize 不处理 JavaScript。试试WWW::Mechanize::FirefoxWWW::ScripterWWW::SeleniumWWW::Mechanize::PhantomJS 或类似的。

    【讨论】:

    • 我正在尝试 Selenium,但我在运行服务器时卡住了 >> java -jar selenium-server-standalone-2.44.0.jar 03:05:27.879 INFO - Started org.openqa.jetty.jetty .Server@2a5330
    • 只是为了未来的观众,不要尝试 WWW::Mechanize::Firefox 和 WWW::Selenium,这两个项目都是 eol
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-04
    • 2012-06-25
    • 1970-01-01
    • 2012-01-09
    • 1970-01-01
    相关资源
    最近更新 更多