当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Login into Intacct with CasperJS to scrape

问题描述:

can someone point me to the an example to make a CasperJS/PhantomJS script that logs in into Intacct and renders a screen cap.

casper = require("casper").create({

waitTimeout: 60000,

viewportSize: {

width: 1024,

height: 768

},

verbose: true,

logLevel: 'debug',

pageSettings: {

loadImages: false,

loadPlugins: false,

userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X)'

}

});

casper.start("https://www.intacct.com/ia/acct/login.phtml");

casper.then(function() {

casper.fill('form[name="iamain"]', {

'.company': 'company',

'.login': 'username',

'.passwd': 'password',

}, true);

});

casper.then(function() {

casper.capture("screen.png");

});

casper.run();

** UPDATED THE CODE FROM THE SUGGESTION BELOW

The image that it saves is just the same login screen.

This is what shows in the cmd screen (UPDATED):

Warning PhantomJS v2.0 not yet released. There will not be any official support for any bugs until stable version is released!

[info] [phantom] Starting...

[info] [phantom] Running suite: 4 steps

[debug] [phantom] opening url: https://www.intacct.com/ia/acct/login.phtml, HTTP GET

[debug] [phantom] Navigation requested: url=https://www.intacct.com/ia/acct/login.phtml, type=Other, willNavigate=true, isMainFrame=true

[debug] [phantom] url changed to "https://www.intacct.com/ia/acct/login.phtml"

[debug] [phantom] Navigation requested: url=https://www.intacct.com/ia/logincontent/product/index.html, type=Other, willNavigate=true, isMainFrame=false

[debug] [phantom] Navigation requested: url=https://www.intacct.com/ia/logincontent/marketing/index.html, type=Other, willNavigate=true, isMainFrame=false

[debug] [phantom] Navigation requested: url=https://www.intacct.com/ia/acct/login.phtml?.topper=%2Fia%2Facct%2Flogin.phtml, type=Other, willNavigate=true, isMainFrame=false

[debug] [phantom] Navigation requested: url=https://googleads.g.doubleclick.net/pagead/viewthroughconversion/1071821189/?random=1427724789483&cv=7&fst=1427724789483&num=1&fmt=1&label=2QNMCIiK0AMQheOK_wM&guid=ON&u_h=1080&u_w=1920&u_ah=1040&u_aw=1920&u_cd=32&u_his=1&u_tz=-240&u_java=false&u_nplug=0&u_nmime=0&frm=1&url=https%3A//www.intacct.com/ia/acct/login.phtml&ref=https%3A//www.intacct.com/ia/acct/login.phtml&vis=1, type=Other, willNavigate=true, isMainFrame=false

[debug] [phantom] Navigation requested: url=https://www.google.com/ads/user-lists/1071821189/?label=2QNMCIiK0AMQheOK_wM&fmt=1&num=1&cv=7&frm=1&url=https%3A//www.intacct.com/ia/acct/login.phtml&ref=https%3A//www.intacct.com/ia/acct/login.phtml&random=2994291944, type=Other, willNavigate=true, isMainFrame=false

[debug] [phantom] Successfully injected Casper client-side utilities

[debug] [phantom] start page is loaded

[info] [phantom] Step anonymous 3/4 https://www.intacct.com/ia/acct/login.phtml (HTTP 200)

[info] [remote] attempting to fetch form element from selector: 'form[name="iamain"]'

[debug] [remote] Set ".company" field value to company

[debug] [remote] Set ".login" field value to username

[debug] [remote] Set ".passwd" field value to ************

[info] [remote] submitting form to login.phtml?.done=frameset.phtml, HTTP POST

[info] [phantom] Step anonymous 3/4: done in 1889ms.

[info] [phantom] Step anonymous 4/4 https://www.intacct.com/ia/acct/login.phtml (HTTP 200)

[debug] [phantom] Capturing page to C:/Users/mycomputer/Desktop/Phantom Test/screen.png

[info] [phantom] Capture saved to C:/Users/mycomputer/Desktop/Phantom Test/screen.png

[info] [phantom] Step anonymous 4/4: done in 2073ms.

[debug] [phantom] Navigation requested: url=https://www.intacct.com/ia/acct/login.phtml?.done=frameset.phtml, type=FormSubmitted, willNavigate=true, isMainFrame=true

[debug] [phantom] url changed to "https://www.intacct.com/ia/acct/login.phtml?.done=frameset.phtml"

[debug] [phantom] Navigation requested: url=https://www.intacct.com/ia/logincontent/product/index.html, type=Other, willNavigate=true, isMainFrame=false

[debug] [phantom] Navigation requested: url=https://www.intacct.com/ia/logincontent/marketing/index.html, type=Other, willNavigate=true, isMainFrame=false

[debug] [phantom] Navigation requested: url=https://www.intacct.com/ia/acct/login.phtml?.topper=%2Fia%2Facct%2Flogin.phtml%3F.done%3Dframeset.phtml, type=Other, willNavigate=true, isMainFrame=false

[debug] [phantom] Navigation requested: url=https://googleads.g.doubleclick.net/pagead/viewthroughconversion/1071821189/?random=1427724790656&cv=7&fst=1427724790656&num=1&fmt=1&label=2QNMCIiK0AMQheOK_wM&guid=ON&u_h=1080&u_w=1920&u_ah=1040&u_aw=1920&u_cd=32&u_his=2&u_tz=-240&u_java=false&u_nplug=0&u_nmime=0&frm=1&url=https%3A//www.intacct.com/ia/acct/login.phtml%3F.done%3Dframeset.phtml&ref=https%3A//www.intacct.com/ia/acct/login.phtml%3F.done%3Dframeset.phtml&vis=1, type=Other, willNavigate=true, isMainFrame=false

[debug] [phantom] Navigation requested: url=https://www.google.com/ads/user-lists/1071821189/?label=2QNMCIiK0AMQheOK_wM&fmt=1&num=1&cv=7&frm=1&url=https%3A//www.intacct.com/ia/acct/login.phtml%3F.done%3Dframeset.phtml&ref=https%3A//www.intacct.com/ia/acct/login.phtml%3F.done%3Dframeset.phtml&random=3619079888, type=Other, willNavigate=true, isMainFrame=false

[debug] [phantom] Successfully injected Casper client-side utilities

[info] [phantom] Done 4 steps in 2821ms

网友答案:

The issue is that the site hasn't loaded yet and won't show the logged in page. Try adding your casper.capture("screen.png"); inside another casper.then() block, this will make casper capture the screenshot after it received the response for the request that got triggered by your actions. May be there is a better way to do it but this has worked for me in several occasions.

分享给朋友:
您可能感兴趣的文章:
随机阅读: