casperjs

Custom casperjs modules

和自甴很熟 提交于 2019-12-02 05:31:36
问题 I've extended my casperjs to use some new methods like this one : casper.getTxt = function(selector) { if(this.exists(selector)) { return this.getHTML(selector); } else { return ''; } }; I've to add these functions on every script that I write. so I made a new file custom.js on the same location where other modules( colorizer.js , mouse.js etc) were placed. custom.js has following code : var require = patchRequire(require); var casper = require('casper').create(); var getTxt = function

Running multiple instances of casperjs

ε祈祈猫儿з 提交于 2019-12-02 02:55:13
I need to run 3 url requests simultaneously.I thought of running 3 casper instances each fetching a url. As a simple example,I tried with 2 instances. var casper=require('casper').create(); casper.start('http://www.google.com'); var casper1=require('casper').create(); casper1.start('http://www.google.com'); casper1.then(function() { casper1.echo('inside'); }); casper1.echo('outside'); casper1.run(); casper.run(); Output shows only 'outside'.Why does'nt it run the casper1.echo('inside'); CasperJS uses a stack of commands that created whenever you use one of the functions from their api (start,

Custom casperjs modules

自作多情 提交于 2019-12-02 02:11:17
I've extended my casperjs to use some new methods like this one : casper.getTxt = function(selector) { if(this.exists(selector)) { return this.getHTML(selector); } else { return ''; } }; I've to add these functions on every script that I write. so I made a new file custom.js on the same location where other modules( colorizer.js , mouse.js etc) were placed. custom.js has following code : var require = patchRequire(require); var casper = require('casper').create(); var getTxt = function(selector) { if(casper.exists(selector)) { return casper.getHTML(selector); } else { return ''; } }; exports

CasperJS dynamic selectlists

亡梦爱人 提交于 2019-12-01 20:11:10
Need help I am scraping data from this website which has a form that contains three selectlists interconnected to each other that is if the any option from the from the first select list is selected this function is called onchange="Javascript:submitForm2(); and the second selectlist is populated. And subsequently if an option from the second selectlist is selected the same js function is called onchange="Javascript:submitForm2();" And finally two submit buttons for this form each call different js function which populate the result. So I checked out the docs and I did not find any info about

Cant get “this.mouse.click()” to work with casperjs

一世执手 提交于 2019-12-01 18:52:22
Im trying to understand casperjs but struggling with this. Can someone pleas tell me why this works (it navigates to http://www.w3schools.com/html/default.asp ): var casper = require('casper').create(); var mouse = require("mouse").create(casper); casper.start('http://www.w3schools.com/'); casper.then(function(){ this.click('a.btn'); }); casper.then(function(){ console.log('Location is now: ' + this.getCurrentUrl()); }); casper.run(); But if i replace this.click('a.btn'); with this.mouse.click('a.btn'); Then it stays on the same page. I thought these where the same. According to Instant

querySelectorAll not recognizing var

坚强是说给别人听的谎言 提交于 2019-12-01 14:28:19
I am using casperjs for some webscraping and am having a strange problem. I want to be able to construct a CSS path from strings and get an array using 'querySelectorAll' like below: var tier = '-ou-'; var index = 'div.list > div > a[href*="' + tier + '"]'; var battles = document.querySelectorAll(index); However, this does not work, and battles returns null. This version works: var links = document.querySelectorAll('div.list > div > a[href*="-ou-"]'); But none other does. I also tried: var index = 'div.list > div > a[href*="-ou-"]'; var battles = document.querySelectorAll(String(index)); and

How can I wait for a socket.io connection to return data using casperJS?

纵饮孤独 提交于 2019-12-01 12:39:16
问题 I am scraping a page which uses socket.io to populate some select tag options. How can I wait for the socket to receive data before evaluating the page? I am using casperJS the socket code (loaded by the target site): socket.on('list', function (data) { $.each(data.match_names, function (id, name) { if (some condition) { /*nothing*/ } else { if (typeof( varname ) == 'function') { $('#myselector').append('<option value="' + id + '">' + name + " " + get_tournament_name(id.substr(0, 4)) + '<

Using CasperJS as a Portable Installation?

泄露秘密 提交于 2019-12-01 12:33:07
I'm trying to run CasperJS in a portable way that doesn't involve setting the path variable in Windows. Currently I have gotten this to partially work by moving the phantomjs executable along with the entire contents of the CasperJS directory to the batchbin folder. I also edited the batch file to make it initialize casperJS using the current directory, which is where all the files are located. Here is my directory with all the files: http://i.imgur.com/ByTjU0s.png My casperjs.bat file: @ECHO OFF set CASPER_PATH=%~dp0 set CASPER_BIN=%CASPER_PATH%bin\ set ARGV=%* call phantomjs "%CASPER_BIN

CasperJS/PhantomJS .then in do/while Loop Doesn't Work

六眼飞鱼酱① 提交于 2019-12-01 11:55:09
Something like this seemed pretty logical to me but caused phantom to wtfcrash (That's what it's called in the log but doesn't give helpful info)... do { casper.then(function() { var targetFound = false; links = this.evaluate(getLinks); var searchResultsAr = []; for (var link in links) { searchResultsAr.push(links[link].replace('/url?q=', '').split('&sa=U')[0]); } for (var result in searchResultsAr) { if (searchResultsAr[result] == target) { targetFound = true; casper.echo(targetFound); break; } } if(targetFound) { break; } }); }while(!targetFound); dasmelch There are different possibilies, if

CasperJS waitForResource: how to get the resource i've waited for

人走茶凉 提交于 2019-12-01 11:40:54
casper.test.begin('Test foo', 1, function suite(test) { casper.start("http://www.foo.com", function() { casper.waitForResource("bar", function(resource) { casper.echo(resource.url); }); }); casper.run(function() { test.done(); }); }); casper.echo returns www.foo.com resource (the one in casper.start ), not the one with "bar". How can I get the resource i've waited for with waitForResource ? You actually waited for the "bar" resource. The problem is that resource inside the then callback function of waitForResource is actually the page resource of the last start or open ( thenOpen ) call. It