有人可以给我指一个例子来制作一个登录 Intacct 并呈现屏幕截图的 CasperJS/PhantomJS 脚本吗?
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();
** 根据下面的建议更新了代码
它保存的图像与登录屏幕完全相同。
这是 cmd 屏幕中显示的内容(已更新):
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
最佳答案
问题是该网站尚未加载,并且不会显示登录页面。尝试将 casper.capture("screen.png");
添加到另一个 casper.then()
block 中,这将使 casper 在收到以下响应后捕获屏幕截图由您的操作触发的请求。可能有更好的方法来做到这一点,但这在很多情况下对我有用。
关于javascript - 使用 CasperJS 登录 Intacct 进行抓取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29337431/