用PhantomJS注入Javascript的正确语法是什么?
What is the right syntax for injecting Javascript with PhantomJS?
我的目标是:
javascript document.getElementById("pickupZip").value = "90049";
document.getElementById("refreshStoresForZipPop").click();
用PhantomJS把放到一个网站中。这是我的inject.js文件上的所有代码,我在控制台:SyntaxError: Expected an identifier but found "document" instead
中得到它,所以我知道它的语法是错误的,尽管我找不到一个显示正确的地方。下面是我的PhantomJS文件代码:
var webPage = require('webpage');
var page = webPage.create();
page.open('http://shop.advanceautoparts.com/p/purolator-classic-air-filter-a24278/5792304-P?navigationPath=L1*14934/', function(status) {
var success = phantom.injectJs('inject.js');
console.log(success);
if (status === "success") {
page.includeJs('http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js', function() {
page.render('advanceautoparts.png');
phantom.exit();
});
}
});
使用evaluate
var webPage = require('webpage');
var page = webPage.create();
page.open('http://shop.advanceautoparts.com/p/purolator-classic-air-filter-a24278/5792304-P?navigationPath=L1*14934/', function(status) {
var success = phantom.injectJs('inject.js');
console.log(success);
if (status === "success") {
page.includeJs('http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js', function() {
page.evaluate(function(s) {
document.getElementById("pickupZip").value = "90049";
document.getElementById("refreshStoresForZipPop").click();
});
page.render('advanceautoparts.png');
phantom.exit();
});
}
});
参考:http://phantomjs.org/api/webpage/method/evaluate.html
相关文章:
- node.js是否具有'match()'方法如果是,语法是什么
- 用于指定元素 ID 的正确 JavaScript 语法是什么
- 在jQuery方法中编写自定义属性的正确语法是什么
- 这段代码的语法是什么
- 将一个函数及其参数传递给另一个函数以执行它的语法是什么
- angular 2中使用的“[()]'语法是什么
- jQuery中的正确语法是什么
- 这个奇怪的setTimeout语法是什么
- 这个 js 语法是什么意思
- 简单的javascript IF语句 - 正确的语法是什么
- 在 Node.js 中删除/释放 Twilio 电话号码的语法是什么?
- 在 JavaScript 中,条件语句中 OR 运算符的正确语法是什么?我错过了什么
- 通过 Excel VBA 引用 Acrobat Javascript 全局变量所需的语法是什么?
- 在回调函数中呈现 Meteor 检索到的数据的正确语法是什么
- 使用 ES6 导入 JSNLog 的正确语法是什么?
- javascript:这段代码的完整语法是什么
- javascript:函数语法是什么意思
- 从 java 脚本调用参数化 ms-access 函数的语法是什么?
- 这个语法是什么意思----->“!!“在 JavaScript 中
- 在 document.write 中用于具有属性的标签的正确语法是什么