2016-12-01 91 views

回答

1

有可能與兩種不同的方式,這將工作:

var casper = require('casper').create({ 
    verbose: true, 
    logLevel: 'debug', 
    waitTimeout: 5000, 
    userAgent: 'Mozilla/5.0 (X11; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0', 
    viewportSize:{width: 1600, height: 900} 
}); 
casper 
.on("error", function(msg){ this.echo("error: " + msg, "ERROR") }) 
.on("page.error", function(msg, trace){ this.echo("Page Error: " + msg, "ERROR") }) 
.on("remote.message", function(msg){ this.echo("Info: " + msg, "INFO") }); 

casper 
    .start("https://www.wikifolio.com/de/de/home", function(){ 
    this.click('div.js-change-country-mode-btn'); 
    this.wait(500,function(){this.click('a.js-login-button')}); 
    this.wait(500,function(){ 
    this.fillSelectors('form[action$=login]', { 
     "input#Username" : "[email protected]", 
     "input#Password" : "<pass>" 
    },true); 
}) 
}) 
    .then(function(){ 
    this 
.capture("Afterlogin.png") 
.wait(5000,function(){ this.capture("Afterlogin2.png") }) 
    }) 
     .run(); 

您可以使用sendKeys() 而不是fillSelectors()
文件:Afterlogin.png
文件:Afterlogin2.png

這將工作太:
可以使用的cookie做到這一點:

var casper = require('casper').create({ 
    verbose: true, 
    logLevel: 'debug', 
    waitTimeout: 5000, 
    userAgent: 'Mozilla/5.0 (X11; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0', 
    viewportSize:{width: 1600, height: 900} 
}); 
casper 
.on("error", function(msg){ this.echo("error: " + msg, "ERROR") }) 
.on("page.error", function(msg, trace){ this.echo("Page Error: " + msg, "ERROR") }) 
.on("remote.message", function(msg){ this.echo("Info: " + msg, "INFO") }); 

//for www.wikifolio.com/de/de/home auth 
phantom.cookies = [{// an array of objects 
    'name'  : 'theAuthCookie', 
    'value' : '<very long string>', 
    'domain' : 'www.wikifolio.com', 
    'path'  : '/', 
    'httponly' : false, 
    'secure' : true, 
    'expires' : (new Date()).getTime() + (1000 * 60 * 60 * 43800) //5 years 
},{ 'name'  : 'DisclaimerCountryPopupV2', 
    'value' : 'de', 
    'domain' : 'www.wikifolio.com', 
    'path'  : '/', 
    'httponly' : false, 
    'secure' : true, 
    'expires' : (new Date()).getTime() + (1000 * 60 * 60 * 43800) }] 

var target = "https://www.wikifolio.com/de/de/alle-wikifolios/suche#/?tags=aktde,akteur,aktusa,akthot,aktint,etf,fonds,anlagezert,hebel&media=true&private=true&assetmanager=true&theme=true&super=true&WithoutLeverageProductsOnly=true&languageOnly=true" 

casper 
    .start(target, function(){ }) 
    .then(function(){ 
    this 
.capture("Afterlogin.png") 
.wait(5000,function(){ this.capture("Afterlogin2.png") }) 
    }) 
     .run(); 
+2

在第二個解決方案,其中是登錄?或者我必須附加登錄名? –

+2

我猜你的登錄信息存儲在'theAuthCookie'的值中? –