【发布时间】:2015-05-05 23:21:35
【问题描述】:
我正在尝试使用 PhantomJS 下载网页,代码如下所示,其中“地址”是网址,“目录”是我下载网页代码的文件路径。
var system = require('system');
var page = require('webpage').create();
var fs = require('fs');
// Set the url address
address = system.args[1];
// Set the file path
var dir = system.args[2];
page.open(address, function () {
fs.write(dir, page.content, 'w');
phantom.exit();
});
这在许多网页中都能正常工作,但在这种情况下(“http://www.lefties.com/es/es/woman/zapatos-c1029521.html”)我看不到产品的 href,因为当我使用 phantomJS 下载或不使用它时,下载的是全屏弹出窗口cookie 订阅。这样就无法在下载的 html 中找到产品 href。
另外,PhantomJS 在我下载的时候显示这个错误:
TypeError: 'null' 不是对象(评估 '$('PopupFullscreen').getElementById('Close').setStyles')
有什么办法可以避免订阅/cookie 弹出窗口吗?
【问题讨论】:
标签: javascript html cookies popup phantomjs