gpt4 book ai didi

javascript - phantomJS JavaScript

转载 作者:行者123 更新时间:2023-11-28 12:44:52 27 4
gpt4 key购买 nike

我正在尝试学习 PhantomJS。我需要登录一个网站,并执行一些基本的爬行。以下代码因此错误而中断:

undefined:12 SyntaxError: Parse error

我的代码:

var loginKronos = function (url, username, password) {

var page = new WebPage();

page.open(url, function (status) {
if (status !== 'success') {
console.log('FAIL to load the address');
};
else {
//t = Date.now() - t;
//console.log('Loading time ' + t + ' msec');
console.log('Loading time ' + t + ' msec');
};

};

var username = 'me';
var password = 'passwd';
var baseurl = 'http://golfing.com/';

loginKronos ( baseurl, username, password );

phantom.exit();

最佳答案

你(至少)忘记了括号。

此外,不要在 if/else 语句的右大括号后添加分号

page.open(url, function (status) {
if (status !== 'success') {
console.log('FAIL to load the address');
} // <---------- removed semicolon
else {
//t = Date.now() - t;
//console.log('Loading time ' + t + ' msec');
console.log('Loading time ' + t + ' msec');
} // <----------- removed semicolon

}); // <------------- added a paren

关于javascript - phantomJS JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8948829/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com