phantomjs 的使用出现不稳定现象, 有时候有结果有时候没结果
命令:phantomjs --output-encoding=gbk test.js http://webscan.360.cn/index/checkwebsite
有时候能够正常返回 diaoyu_sec 的值, 但有个别时候却找不到diaoyu_sec的值 , 返回结果提示: 'null' is not an object
请问是不是因为网速问题导致这种现象呢? 有什么好的补救解决方法?
test.js文件如下:
var page = require('webpage').create(),
system = require('system'),
address;
if (system.args.length === 1)
{
phantom.exit(1);
}
else
{
address = system.args[1];
page.open(address, function (status)
{
var ua = page.evaluate(function () {
return document.getElementById('diaoyu_sec').textContent;
});
console.log(ua);
phantom.exit();
}
);
}
有时候能够正常返回 diaoyu_sec 的值, 但有个别时候却找不到diaoyu_sec的值 , 返回结果提示: 'null' is not an object
请问是不是因为网速问题导致这种现象呢? 有什么好的补救解决方法?
test.js文件如下:
var page = require('webpage').create(),
system = require('system'),
address;
if (system.args.length === 1)
{
phantom.exit(1);
}
else
{
address = system.args[1];
page.open(address, function (status)
{
var ua = page.evaluate(function () {
return document.getElementById('diaoyu_sec').textContent;
});
console.log(ua);
phantom.exit();
}
);
}
...全文
相关推荐
phantomjs-prebuilt
phantomjs-prebuilt"包解决了npm安装过程中可能出现的依赖问题,比如网络连接不稳定导致的下载失败或者特定平台的兼容性问题。
phantomjs-node:使用同步样式按节点调用phantomjs
它通过内部实现的回调机制,使得PhantomJS的调用能够像传统的同步函数一样等待结果返回。
使用phantomjs进行网页抓取的实现代码
**页面内容提取**: 利用phantomjs的evaluate()方法,可以执行页面内的JavaScript代码,并获取执行结果。这允许开发者执行DOM操作,并通过回调函数将结果输出。4.
使用Phantomjs和Node完成网页的截屏快照的方法
"这篇资源介绍了如何使用PhantomJS和Node.js来实现网页的截屏快照功能,主要针对Windows环境下进行配置和代码实现的步骤进行了详细说明。"在Web开发中,有时候我们需要对网页内容
C#使用Selenium+PhantomJS抓取数据
- 最后,`Console.Read()`防止控制台窗口立即关闭,便于查看输出结果。3.


