2014-01-25 3 views
1

나는이 코드를 사용하여 casperJS를 사용하여 LinkedIn에 로그인했지만 로그인하지 않은 상태에서 "환영합니다! LinkedIn"이어야하지만 돌아 오는 "세계에서 가장 큰 전문적인 네트워크 | LinkedIn"및 문서 여야합니다. 위치는 웹 사이트 URL과 다르지만 실행 후 돌아 오는 웹 사이트 URL이어야합니다.CasperJS가 LinkedIn에 로그인

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: '[email protected]', 
     session_password: 'password' 
    }, true); 
}); 

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

casper.run(); 

이 코드에서 잘못된 것은 무엇입니까?

답변

2

스크립트가 코드를 너무 빠르게 평가한다고 생각합니다. (당신이 캐스퍼 1.1 스크립트를 실행하는 경우)

그래서 나는이 문장에 casper.thenEvaluate을 대체 할 수 있습니다 : 또한

casper.waitForUrl(/nhome/, function() { 
     this.evaluate(function() { 
      console.log("Page Title " + document.title); 
      console.log("Your name is " + document.location); 
     }); 
}); 

, 당신은 대기로 시도 할 수

casper.wait(2000, function() { 
     this.evaluate(function() { 
      console.log("Page Title " + document.title); 
      console.log("Your name is " + document.location); 
     }); 
}); 

더 이 함수에 대한 정보는 다음과 같습니다. http://docs.casperjs.org/en/latest/modules/casper.html#waitforurl

+0

게시 한 코드를 테스트 했습니까? 이 오류가 발생합니다. [오류] [팬텀] 5000ms의 대기 제한 시간이 만료되었습니다. 5000ms의 대기 제한 시간이 만료되었습니다. ' – scottydelta

+0

그래, 작동하지만, 나는 어쩌면 linkedin 내게 같은 페이지 URL을 제공하지 않습니다. 기다리십시오 (2000, function() {}); –

+0

뉴스가 있으십니까? 감사. –

0

제 경우에는 다음과 같이했을 때 이것을 보관했습니다 :

this.evaluate(function() { 
    $('#login-email').val('[email protected]'); 
    $('#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); 

텍스트 필드에 내용을 입력하지 않으면 제출할 수 없다고 생각합니다.

관련 문제