casper.then(function(){
phone_number = '7wqeqwe6';
phone_password = 'Teqweqweqw34';
});
casper.thenEvaluate(function(phone,password) {
document.querySelector('input#myTMobile-phone').setAttribute('value',phone);
document.querySelector('input#myTMobile-password').setAttribute('value',password);
// document.querySelector('form').submit();
}, {
phone : phone_number,
password : phone_password
});
Run Code Online (Sandbox Code Playgroud)
这引起了我的兴趣
string(307)"[37; 41; 1mFAIL [0m ReferenceError:找不到变量:phone_number
有没有办法通过params来评估方法?
我最近尝试登录网站,迫使我接受cookie.我正在使用phantomJs和casperJs.我写了一个应该处理登录的小脚本,但它将我重定向到一个告诉我必须接受cookie的网站.电子邮件和密码只是占位符.
我想登录的网站是https://de.buyvip.com/.但是我需要点击按钮Anmelden mit Amazon才能登录我的亚马逊帐户.其他登录表单不起作用.(这导致这个长网址,我只是从我的浏览器复制它)
有人能帮我吗?
这是脚本:
var casper = require("casper").create()
var fs = require('fs');
var page = "https://www.amazon.de/ap/signin?openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&pageId=quarterdeckde&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&clientContext=280-1158662-4507036&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&marketPlaceId=A38GABX06X24K&openid.assoc_handle=quarterdeckde&openid.return_to=https%3A%2F%2Fde.buyvip.com%2Fsignin&openid.pape.max_auth_age=0&siteState=http%3A%2F%2Fde.buyvip.com%2Fhomepage%3Fhash%3DM";
phantom.cookiesEnabled = true;
casper.start(page, function()
{
console.log("started");
this.fill('form#ap_signin_form', {
'email' : 'myMail',
'password' : 'myPass'
}, true);
});
casper.then(function()
{
fs.write("test.html", this.getHTML(), "w");
});
casper.run();
Run Code Online (Sandbox Code Playgroud) 我有以下简单的代码:
var casper = require("casper").create({
}),
utils = require('utils'),
http = require('http'),
fs = require('fs');
casper.start();
casper.thenOpen('http://www.yahoo.com/', function() {
casper.capture('test.png');
});
casper.on('http.status.404', function(resource) {
this.echo('wait, this url is 404: ' + resource.url);
});
casper.run(function() {
casper.exit();
});
Run Code Online (Sandbox Code Playgroud)
有没有办法捕捉http.status代码而不管它是什么?现在我可以在doc中看到显示捕获特定代码事件的方法.如果我只想看看它是什么怎么办?
我想让我的casper登录并在会话期间保持登录状态.可能吗?如果是这样,怎么样?
例如,我有一个经常需要执行的步骤,例如在某些测试之前用户登录.
如何为CasperJS编写可重用的代码块?他们扩展CasperJS的文档仅针对一个文件编写......
谢谢!
PHP使用exec()命令调用CasperJS .在CasperJS完成其工作(例如检索网页的某些部分)之后,如何将检索到的数据返回给PHP?
我试图通过casperjs捕获站点console.log和console.error.在console.log的情况下,我有工作代码:
casper.on('remote.message', function(message) {
this.echo('remote message caught: ' + message);
});
Run Code Online (Sandbox Code Playgroud)
但我无法弄清楚如何捕捉console.error.我需要这个来捕获任何资源错误(比如找不到图像).
成功登录后,我尝试导航到https://plus.google.com/u/0/?tab=wX但casperjs挂起.
最后一个输出是:
[debug] [phantom] Navigation requested: url=https://clients6.google.com/static/proxy.html?jsh=m;/_/scs/apps-static/_/js/k=oz.gapi.en.Z6gj5B0lzyA.O/m=__features__/am=IQ/rt=j/d=1/t=zcms/rs=AItRSTPU0_gqMrtQ831rDdqYv8Z1ZnxcbA#parent=https://tal kgadget.google.com&rpctoken=640385943, type=Other, willNavigate=true, isMainFrame=false [debug] [phantom] Navigation requested: url=https://plus.google.com/hangouts/_/pre?hl=en&authuser=0, type=Other, willNav igate=true, isMainFrame=false [debug] [phantom] Navigation requested: url=https://plus.google.com/u/0/_/blank, type=Other, willNavigate=true, isMainFr ame=false
好像它挂在了环聊的iframe上.如何阻止加载某些内部URL?
我试过了:
// try to hide hangouts
casper.on('page.resource.requested', function (requestData, request) {
if (requestData.url.indexOf('plus.google.com/hangouts') != -1) {
this.echo('RESOURCE ABOTRED ' + requestData.url);
request.abort();
return;
}
});
casper.on('navigation.requested', function (url, navigationType, navigationLocked, isMainFrame) {
if (url.indexOf('plus.google.com/hangouts') != -1 || url.indexOf('talkgadget') != -1) {
// this.echo('ALARM!!!' + url);
willNavigate = false; …Run Code Online (Sandbox Code Playgroud) 嗨我在我的Web应用程序中使用jquery和Ajax作为前端,所以我正在使用casperjs自动化测试环境.因为使用了jquery - ajax,我无法跟踪应用程序是否加载了页面以及许多其他事件.所以在开发时我想在浏览器中查看操作而不是文本模式.
有没有可能查看通过浏览器操作运行的测试脚本?
使用slimerjs引擎在casperjs中运行测试脚本时,我无法查看完整的窗口.任何人都可以帮我增加mozila浏览器窗口大小
casperjs ×10
javascript ×6
phantomjs ×4
node.js ×2
cookies ×1
login ×1
php ×1
slimerjs ×1
web-crawler ×1
web-scraping ×1