Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.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
CasperJS登录到LinkedIn_Linkedin_Casperjs - Fatal编程技术网

CasperJS登录到LinkedIn

CasperJS登录到LinkedIn,linkedin,casperjs,Linkedin,Casperjs,我正在使用此代码使用casperJS登录LinkedIn,但它不起作用,登录后的标题应为“欢迎!LinkedIn”,但返回“世界上最大的专业网络| LinkedIn”,文档位置应不同于网站url,但执行后返回的网站url var casper = require('casper').create({ verbose: true, logLevel: 'debug', pageSettings: { loadImages: false, // The WebPa

我正在使用此代码使用casperJS登录LinkedIn,但它不起作用,登录后的标题应为“欢迎!LinkedIn”,但返回“世界上最大的专业网络| LinkedIn”,文档位置应不同于网站url,但执行后返回的网站url

var casper = require('casper').create({   
verbose: true, 
logLevel: 'debug',
pageSettings: {
     loadImages:  false,         // The WebPage instance used by Casper will
     loadPlugins: false,         // use these settings
     userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4'
}
});

// print out all the messages in the headless browser context
casper.on('remote.message', function(msg) {
    this.echo('remote message caught: ' + msg);
});

// print out all the messages in the headless browser context
casper.on("page.error", function(msg, trace) {
    this.echo("Page Error: " + msg, "ERROR");
});

var url = 'https://www.linkedin.com/';

casper.start(url, function() {
   // search for 'casperjs' from google form
   console.log("page loaded");
   this.test.assertExists('form#login', 'form is found');
   this.fill('form#login', { 
        session_key: 'username@gmail.com', 
        session_password:  'password'
    }, true);
});

casper.thenEvaluate(function(){
   console.log("Page Title " + document.title);
   console.log("Your name is " + document.location ); 
});

casper.run();

我在这段代码中做错了什么?

我认为脚本对代码的计算速度太快了

因此,我将用以下句子替换casper.thenEvaluate(如果您使用casper 1.1运行脚本):

还有,你可以用wait试试

 casper.wait(2000, function() {
      this.evaluate(function() {
          console.log("Page Title " + document.title);
          console.log("Your name is " + document.location ); 
      });
 });
有关此功能的详细信息:

在我的例子中,当我做这样的事情时,我只是将其存档:

this.evaluate(function() {
    $('#login-email').val('EMAIL@mail.co');
    $('#login-email').focus();
});

this.page.sendEvent('keypress', this.page.event.key.M, null, null, 0x02000000);
this.capture('p1.1.png');

this.evaluate(function() {
    $('#login-password').val('PASSWORD');
    $('#login-password').focus();
});

//change to the last character of your password.
this.page.sendEvent('keypress', this.page.event.key[3]); 

this.page.sendEvent('keypress', this.page.event.key.Enter);
this.page.sendEvent('keypress', this.page.event.key.Enter);

我相信他们不会启用提交,除非您在文本字段中输入内容。

您是否测试了发布的代码?我收到此错误
[error][phantom]5000毫秒的等待超时已过期,正在退出。5000毫秒的等待超时已过期,正在退出是的,它是有效的,但我是法国人,所以linkedin可能不会为我提供相同的页面URL。尝试使用wait(2000,函数(){});
this.evaluate(function() {
    $('#login-email').val('EMAIL@mail.co');
    $('#login-email').focus();
});

this.page.sendEvent('keypress', this.page.event.key.M, null, null, 0x02000000);
this.capture('p1.1.png');

this.evaluate(function() {
    $('#login-password').val('PASSWORD');
    $('#login-password').focus();
});

//change to the last character of your password.
this.page.sendEvent('keypress', this.page.event.key[3]); 

this.page.sendEvent('keypress', this.page.event.key.Enter);
this.page.sendEvent('keypress', this.page.event.key.Enter);