Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/453.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 下载带有PhantomJS的网页_Javascript_Html_Cookies_Popup_Phantomjs - Fatal编程技术网

Javascript 下载带有PhantomJS的网页

Javascript 下载带有PhantomJS的网页,javascript,html,cookies,popup,phantomjs,Javascript,Html,Cookies,Popup,Phantomjs,我正在尝试使用PhantomJS下载一个网页,代码如下所示,其中“address”是url,“dir”是我下载网页代码的文件路径 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.

我正在尝试使用PhantomJS下载一个网页,代码如下所示,其中“address”是url,“dir”是我下载网页代码的文件路径

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();
});
这在许多网页中都能正常工作,但在本例中(“”),我看不到产品的href,因为当我使用phantomJS或不使用phantomJS下载时,下载的是一个带有cookie订阅的全屏弹出窗口。这使得无法在下载的html中找到产品href

此外,PhantomJS在我下载时显示此错误:

TypeError:'null'不是对象(计算'$('PopupFullscreen')。getElementById('Close')。setStyles')

有没有办法避免订阅/cookie弹出窗口


嗯,在脚本中使用cookie(存储在我的浏览器中)可以解决这个问题。有关更多信息,请检查:

像这样的Cookie模式对话框现在很常见。您几乎总是可以关闭这些对话框。单击“关闭”按钮将其关闭

仅仅因为有这个模型对话框,并不意味着你不能访问它背后的DOM。标记仍然存在(除了可能由于TypeError而丢失的标记)

出现该错误消息,因为页面JavaScript使用了一些在PhantomJS 1.x中未实现的功能。如果您使用PhantomJS2,它将消失