casperjs

CasperJs loads json data from a local file

江枫思渺然 提交于 2019-12-03 12:24:56
Is there any convenient way to load a local JSON file into a variable with CasperJs? I saw someone suggest to use $.getJSON(filename, function() ... I have the following working on CasperJS 1.1-beta1 and PhantomJS 1.9.1 test.json { "test": "hello" } test.js var json = require('test.json'); require('utils').dump(json); casper.echo(json.test); // "hello" The solution proposed by @hexid worked for me with one change, i added a './' before the file address to denote it is a local file. test.json { "test": "hello" } test.js var utils = require('utils'); var json = require('./test.json'); utils.dump

CasperJS : Why does my url change to about:blank when my page is loaded?

与世无争的帅哥 提交于 2019-12-03 12:13:21
问题 I'm a beginner at PhantomJS/CasperJS. I just want to start a session and verify that it's OK. Here's my code: var casper = require('casper').create({ verbose: true, logLevel: 'debug', pageSettings: { loadImages: false, loadPlugins: false, userAgent: 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 Edge/12.0' } }); casper.on('remote.message', function(msg) { this.echo('remote message caught: ' + msg); }); casper.on("page.error",

CasperJS click() doesn't load new html

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to use CasperJS' click() to follow a link which generates a modal on the current screen. When I query the proper selector and click it in the browser console using document.querySelector().click() it works, but even when I casper.evaluate() this it doesn't work. I found someone who had a very similar problem, but his question remains unanswered, and I am experiencing almost identical problems. casperjs button click doesn't navigate to next page the code I'm currently using is this.waitForSelector('div.talk-sharing__tools a.rate

CasperJS: Configure proxy options inside code

喜欢而已 提交于 2019-12-03 04:10:37
I was wondering how we could set cli parameters inside our code and not by placing them at the end of our command like this: casperjs casper_tor.js --proxy=127.0.0.1:9050 --proxy-type=socks5 I've tested things like that but it didn't work: var casper=require('casper').create(); casper.cli.options["proxy"] = "127.0.0.1:9050"; casper.cli.options["proxy-type"] = "socks5"; ... casper.run(); What I'm trying to achieve is to set new proxies inside my code and to scrap my new ip address from whatsmyip.com to check that everything is right (I'm writing bots that will frequently change their proxies).

setInterval and this.wait in casper.js

99封情书 提交于 2019-12-03 03:41:16
I need to make a loop of 3 times and 2 seconds in between each iteration . I tried these 3 options: Option 1 var casper = require('casper').create({ verbose: false, logLevel: 'debug' }); casper.start("http://google.com"); casper.on('remote.message', function(msg) { this.echo('remote message caught: ' + msg); }) casper.thenEvaluate(function() { var x = 0; var intervalID = setInterval(function () { console.log("Using setInternal " + x); if (++x === 3) { window.clearInterval(intervalID); } }, 2000); }); casper.run(); Observation : Nothing appeared because the script ended right away before the

CasperJS : Why does my url change to about:blank when my page is loaded?

☆樱花仙子☆ 提交于 2019-12-03 02:44:43
I'm a beginner at PhantomJS/CasperJS. I just want to start a session and verify that it's OK. Here's my code: var casper = require('casper').create({ verbose: true, logLevel: 'debug', pageSettings: { loadImages: false, loadPlugins: false, userAgent: 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 Edge/12.0' } }); casper.on('remote.message', function(msg) { this.echo('remote message caught: ' + msg); }); casper.on("page.error", function(msg,trace) { this.echo("Page Error: " + msg, "ERROR"); }); casper.start('https://www.google.fr');

Cannot find module 'casper' when invoking through PhantomJS

匿名 (未验证) 提交于 2019-12-03 02:18:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I installed PhantomJS in C:\xampp\htdocs\phantom and also I installed CasperJS in this folder C:\xampp\htdocs\casper When I tried to run these sample code on casper site using phantomjs test.js command: var casper=require('casper').create(); casper.start('http://google.fr/'); casper.thenEvaluate(function(term) { document.querySelector('input[name="q"]').setAttribute('value', term); document.querySelector('form[name="f"]').submit(); }, 'CasperJS'); casper.then(function() { // Click on 1st result link this.click('h3.r a'); }); casper.then

Why does CasperJS form submit not redirect to the next page?

匿名 (未验证) 提交于 2019-12-03 01:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This is my first casper test, so I'm still struggling with the basics. I would like to fill in the username and password on my login form, then submit it. And then confirm if a 'log off' link is rendered on the next page (confirming that the user has been logged in). But as far as I can tell, when then is called, the url is still the same. Looks like no post or redirect to the next page is happening. What am I doing wrong? casper.start "http://test.local.mycompany.local/", -> @echo 'at ' + @getCurrentUrl() @fill 'form', { UserAlias : 'joe',

How to use fillSelectors in casperjs

匿名 (未验证) 提交于 2019-12-03 01:26:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I need to get some content from the page, but if I use fillSelectors() the content is not load. Maybe i need use evaluate() , but i dont undestend where and how. var casper = require ( 'casper' ). create () casper . start ( 'http://console.matomycontentnetwork.com/' , function () { this . fillSelectors ( 'form#login-form' , { 'input[name="username"]' : 'jpost' , 'input[name="password"]' : 'matomy123' }, true ); this . clickLabel ( "Sign In" , 'button' ); }); casper . then ( function () { var start_date = '09/01/2015' ; var end_date

php execution phantom js works but casperjs does not work permission denied

匿名 (未验证) 提交于 2019-12-03 01:12:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: okay so i am running centos 6.5 with zpanel setup. this then has phantom js and casperjs both setup and working it the /usr/local/bin directory. i use this php command for phantomjs and casperjs echo exec('/usr/local/bin/casperjs --version 2>&1'); phantomjs works fine but casperjs gives me this error sh: /usr/local/bin/casperjs: Permission denied can anyone out there help me fix this problem it is just a pain output for ls -al casperjs [root@cyber-hosted ~]# ls -al casperjs total 100 drwxr-xr-x 10 apache root 4096 Feb 4 15:49 . dr-xr-x---. 5