【问题标题】:Scraping dynamic page content phantomjs抓取动态页面内容phantomjs
【发布时间】:2012-12-10 16:40:52
【问题描述】:

我的公司正在使用一个网站,其中包含我们所有的常见问题解答和客户问题。我们计划通过并清除所有旧数据并输入新数据,并且该服务没有备份或存档选项来解决我们不想再出现的问题。

我已经通过并尝试使用 perl 和 mechanize 对站点进行景观化,但我错过了页面上的客户 cmets,因为它们是通过 ajax 加载的。我查看了 phantomjs 并且可以使用示例页面将页面保存到图像中,但是,我想获得页面的完整页面 html 转储,但不知道如何。我在我们的网站上使用了这个示例代码

var page = new WebPage();

page.open('http://espn.go.com/nfl/', function (status) {
//once page loaded, include jQuery from cdn
page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function() {
//once jQuery loaded, run some code
//inserts our custom text into the page
page.evaluate(function(){$("h2").html('Many NFL Players Scared that Chad Moon Will Enter League');});
//take screenshot and exit
page.render('espn.png');
phantom.exit();

});

});

有没有一种方法可以使用 phantomjs 来获取数据的完整页面转储,类似于我在 chrome 中查看源代码?我可以用 perl + mechanize 做到这一点,但不知道如何使用 phantomjs 做到这一点。

【问题讨论】:

标签: javascript html web-scraping phantomjs


【解决方案1】:

您可以使用page.content 获取完整的 HTML DOM

【讨论】:

    【解决方案2】:

    如果你想使用 PhantomJS 进行抓取,我会推荐 pjscrape http://nrabinowitz.github.com/pjscrape/

    【讨论】:

      猜你喜欢
      • 2018-02-17
      • 1970-01-01
      • 2019-01-13
      • 1970-01-01
      • 2020-05-24
      • 1970-01-01
      • 1970-01-01
      • 2012-02-11
      • 2013-07-10
      相关资源
      最近更新 更多