casperjs

How Do I use jQuery in CasperJS?

被刻印的时光 ゝ 提交于 2019-11-26 20:10:19
问题 casper.start(URL, function() { casper.page.injectJs('C:/Users/Mike/Documents/n1k0-casperjs-bc0da16/jquery-1.10.2.min.js'); var names = $('span.author-name'); this.echo(names); this.exit(); } ReferenceError: Can't find variable: $ What do I do? I've tried this too when creating the casper instance: var casper = require('casper').create({ // I've tried both commented lines below // clientScripts: ['C:/Users/Mike/Documents/n1k0-casperjs-bc0da16/jquery-1.10.2.min.js'] // clientScripts: ['includes

Reliably detecting PhantomJS-based spam bots

北城以北 提交于 2019-11-26 15:38:24
问题 Is there any way to consistently detect PhantomJS/CasperJS? I've been dealing with a spat of malicious spambots built with it and have been able to mostly block them based on certain behaviours, but I'm curious if there's a rock-solid way to know if CasperJS is in use, as dealing with constant adaptations gets slightly annoying. I don't believe in using Captchas. They are a negative user experience and ReCaptcha has never worked to block spam on my MediaWiki installations. As our site has no

How to login into a website with CasperJS?

让人想犯罪 __ 提交于 2019-11-26 15:21:03
问题 How can I login with CasperJS by submitting a form. I searched google and haven't found any good examples about it. 回答1: You will need to use Casper fill() function. Below is an example which login to Facebook and print out your name after login. Note that you need to put in your username and password: var casper = require('casper').create({ verbose: true, logLevel: 'debug', pageSettings: { loadImages: false, // The WebPage instance used by Casper will loadPlugins: false, // use these

How can I catch and process the data from the XHR responses using casperjs?

断了今生、忘了曾经 提交于 2019-11-26 14:38:17
The data on the webpage is displayed dynamically and it seems that checking for every change in the html and extracting the data is a very daunting task and also needs me to use very unreliable XPaths. So I would want to be able to extract the data from the XHR packets. I hope to be able to extract information from XHR packets as well as generate 'XHR' packets to be sent to the server. The extracting information part is more important for me because the sending of information can be handled easily by automatically triggering html elements using casperjs. I'm attaching a screenshot of what I

Grab the resource contents in CasperJS or PhantomJS

我的梦境 提交于 2019-11-26 14:15:04
问题 I see that CasperJS has a "download" function and an "on resource received" callback but I do not see the contents of a resource in the callback, and I don't want to download the resource to the filesystem. I want to grab the contents of the resource so that I can do something with it in my script. Is this possible with CasperJS or PhantomJS? 回答1: This problem has been in my way for the last couple of days. The proxy solution wasn't very clean in my environment so I found out where phantomjs

console.log doesn't work in CasperJS' evaluate with setTimeout

邮差的信 提交于 2019-11-26 13:57:23
问题 Why when I use console.log in evaluate , it works: casper.then(function() { this.evaluate( function() { console.log('hello'); }); }); But this doesn't work: casper.then(function() { this.evaluate( function() { setTimeout( function() {console.log('hello');}, 1000); }); }); 回答1: Because you're mixing up casperjs and remote page environments. The evaluate function will execute code within the remote page env, so the console.log call won't output anything. If you want to catch remote console.log

CasperJS bind issue

大憨熊 提交于 2019-11-26 13:48:57
I'm trying to reach an instagram page, but with no luck. I keep getting the error and a blank screenshot. Error text: TypeError: 'undefined' is not a function (evaluating 'a.createDescriptor.bind(null,t)') Casperjs --version is 1.1.0-beta3. Basically I use the following code: var casper = require('casper').create({ verbose: true, logLevel: 'debug', pageSettings: { userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4' }, loadPlugins: true }); casper.on( 'page.error', function (msg, trace) { this.echo( 'Error: ' + msg,

downloading a file that comes as an attachment in a POST request response in PhantomJs

泄露秘密 提交于 2019-11-26 13:17:49
I want to download a CSV file, it is generated on a button click through a POST request. I researched to my best on casperJs and phantomJS forums and returned empty handed. In a normal browser like firefox, a browser download dialog window appears after the post request. How to handle this case in PhantomJS TTP/1.1 200 OK Cache-Control: private Content-Type: text/html; charset=utf-8 Content-Encoding: gzip Vary: Accept-Encoding Server: Microsoft-IIS/7.5 Content-disposition: attachment;filename=ExportData.csv X-AspNet-Version: 2.0.50727 X-Powered-By: ASP.NET Date: Fri, 19 Apr 2013 23:26:40 GMT

Why doesn't this.evaluate return DOM nodes correctly?

拟墨画扇 提交于 2019-11-26 12:48:45
问题 I\'m trying to get an object from a web page through the evaluate() method so I can work with it outside the scope of evaluate . The element selected with name symbol is a <select> tag with 148 <options> (=dropdown menu). casper.then(function () { var elmnt = this.evaluate(function () { return document.getElementsByName(\"symbol\")[0]; }); console.log(elmnt.options[14].index); }); //Returns TypeError: \'null\' is not an object (evaluating \'elmnt.options[14].index\') casper.then(function () {

What must be wrapped in then() statements in CasperJS? How to determine execution order of sync/async functions?

时光毁灭记忆、已成空白 提交于 2019-11-26 12:25:02
问题 I\'m having something of a hard time determining what is asynchronous and what is not while running CasperJS, what must be wrapped in then() statements, and what is going to be evaluated when. I\'ll run into a problem somewhere that has to do with a fall-through break statement, variable scope, or the evaluate() statement, and I\'ll start wrapping all my code in then() statements... which turns out to not be the problem. I notice that my code runs on two levels when I step through it, an