Phantomjs检查javascript是否存在并且正在工作
Phantomjs check if javascript exists and is working
我对Phantomjs很陌生,并且开始了解如何使用它。然而,所有的半高级教程都没有涵盖我想要使用Phantomjs的目的。
现在我的问题是,我该如何检查Javascript是否在网站上处于活动状态,以及它是否正常工作(即不会在控制台中抛出错误)。
我希望有人能为我指明正确的方向,或者知道如何做到这一点。
您可以使用webpage.evaluate方法与打开的页面进行交互:
var page = require('webpage').create();
page.open('http://m.bing.com', function(status) {
var title = page.evaluate(function(s) {
//what you do here is done in the context of the page
//this console.log will appear in the virtual page console
console.log("test")
//here they are just returning the page title (tag passed as argument)
return document.querySelector(s).innerText;
//you are not required to return anything
}, 'title');
console.log(title);
phantom.exit(); //closes phantom, free memory!
});
为了查看虚拟页面控制台,您必须添加onConsoleMessage回调:
page.onConsoleMessage = function(msg, lineNum, sourceId) {
console.log('CONSOLE: ' + msg + ' (from line #' + lineNum + ' in "' + sourceId + '")');
};
EDIT:默认情况下执行javascript。
相关文章:
- 由于响应中不存在“Access Control Allow Origin”标头,跨域请求停止工作
- 由于存在标签('#')特殊字符,URL无法工作
- 这个get方法似乎可以工作,但控制台中存在错误
- PHP表单输出保存在jquery的Excel工作表中
- MongoDB 查找检查是否存在未按预期工作
- Phantomjs检查javascript是否存在并且正在工作
- 数组中是否存在不工作的值
- Javascript即使存在于源代码中也无法工作
- 由于回调结构中可能存在错误,无法使超时工作
- AngularJS-ng斗篷按钮不工作(闪烁仍然存在)在铬-ng斗篷不工作'由于某种原因,它甚至没有被添加到CS
- 当URL中存在查询字符串时,Jquery表单提交无法工作
- 匹配,除非存在“转义”字符;必须联机和背靠背工作
- JS -画布从图像文件-工作仅与浏览器缓存存在
- 在jQuery中通过AJAX发送表单,然后保存在MySQL中,但不工作
- jQuery AJAX检查邮件是否存在于数据库中,但由于某些原因无法工作
- 当函数中存在多个时,javascript/DOM中的removeChild无法正常工作
- 检查图片是否存在,但url不能在所有浏览器中工作
- URL重定向基于输入,但如果输入URL不存在,则不重定向无法使PHP工作
- Css /javascript缓存在firefox(和其他浏览器)是如何工作的
- 在进行Javascript密集型工作时,将所有样式保存在CSS文件中有什么好处