scraperjs :网页抓取的代码不起作用



我基本上是在写一个小的网络抓取代码。最初我选择了 NodeJS+Request+Cheerio 来抓取网站,但后来我意识到 Cheerio 仅适用于静态网页,不适用于那些使用 JS 加载 DOM 对象的网页。

所以后来我选择了ScraperJS,因为它有Static_Dynamic ContentScraper。 我已经设置了此处指定的所有依赖项:https://github.com/ruipgil/scraperjs

但是我的代码仍然不起作用,这是他们的 github 存储库中给出的示例代码。 平台:视窗7,运行通过CMD:节点file_name.js

法典:

var scraperjs = require('scraperjs');
console.log("a2");
scraperjs.DynamicScraper.create('https://news.ycombinator.com/')
.scrape(function($) {
return $(".title a").map(function() {
return $(this).text();
}).get();
})
.then(function(news) {
console.log(news);
})

根据这个问题,它来自phantomJS,为了使DynamicScraper工作,必须

降级。你必须将phantomJS降级到1.9.8版本,或者使用4.8版本的NodeJS。

相关内容

最新更新