javascript - 使用 CasperJS 登录 Intacct 进行抓取

标签 javascript phantomjs casperjs

有人可以给我指一个例子来制作一个登录 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/

相关文章:

javascript - SammyJS 无法与 Django 一起使用

node.js - 使用(moSTLy)一个代码库构建动态 HighCharts 和图像 Highcharts?

javascript - Phantomjs:如何让 Casperjs 在我的 Web 应用程序上工作

javascript - NodeJS循环模块应用程序结构

javascript - 响应对象未在更新面板中返回 Excel 流?

python - 使用 Webdriver 和 PhantomJS 记录 HTTP 流量

javascript - (Chrome DevTools) querySelector 返回 null,即使元素明显存在于页面上

javascript - 使用 CasperJS 计算 iFrame 中的每个元素

javascript - 如何从此casperjs代码中消除堆栈溢出(使用setTimeout)?

javascript - Angular - 使用 ng-style 更改 css