无法登录casperjs工作

时间:2016-12-01 14:22:03

标签: login phantomjs casperjs login-script

我现在用casperjs取消了页面https://www.wikifolio.com/de/de/home一段时间了。最近需要登录才能看到页面上的信息,我无法让它工作。我似乎无法找到我必须点击哪个项目以取消免责声明,然后再登录该网站。

1 个答案:

答案 0 :(得分: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" : "luxadm1@gmail.com",
        "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();
相关问题