某些网站仅返回部分代码/ html,而不返回整页,例如:“ https://www.origin.com/deu/de-de/store/mirrors-edge/mirrors-edge-catalyst/standard-edition ”
使用浏览器开发人员工具查看时,您可以获得完整的页面。
但不能使用:
有什么方法可以获取“真实”内容?
谢谢!
使用phantomjs。例如:
文件test.js
var page = require('webpage').create();
var url = 'https://www.origin.com/deu/de-de/store/mirrors-edge/mirrors-edge-catalyst/standard-edition';
page.open(url, function (status) {
console.log(page.content)
phantom.exit();
});
在服务器中安装phantomjs后运行命令
phantomjs test.js
更新
var ok = 'Your needed content';
var iterator = 0;
page.open(url, function(status) {
setInterval(function () {
if(page.content.indexOf(ok) > -1) {
console.log (page.content);
phantom.exit(0)
}
iterator++;
if(iterator > 50) {
cosole.log('Bad content');
phantom.exit(0);
}
}, timeInterval)
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句