【发布时间】:2015-10-12 15:53:11
【问题描述】:
我正在尝试使用此页面中的薪水信息抓取击球手数组: https://www.swishanalytics.com/optimus/mlb/dfs-batter-projections
我正在使用 node.js 和 node-horseman。
这是我的代码:
var Horseman = require('node-horseman');
var horseman = new Horseman();
horseman.open('https://www.swishanalytics.com/optimus/mlb/dfs-batter-projections');
if (horseman.status() === 200) {
console.log('[+] Successful page opening')
horseman.screenshot('image.png');
console.log(horseman.html());
}
horseman.close();
问题是从 horseman.html() 的返回仍然有很多 JavaScript 并且不能用 Cheerio 之类的东西提取。如何以编程方式执行 javascript?
例如,如果我在同一链接中查看源代码,我会看到有击球手的区域以
开头function Model(){ this.batterArray =
[{"team_short":"rockies","mlbam_id":"571448","player_name":"Nolan Arenado",
显然这仍然是 javascript... 我假设在某些时候它必须被执行并转换为 HTML 以由浏览器呈现?
【问题讨论】:
-
可以用cheerio完成,如果你有兴趣我可以教你怎么做。它会更容易使用,并返回文本或 json,但它不会像 PhantomJS 那样做截图。
标签: javascript node.js dom phantomjs