casperjs

How can I make casperjs repeat a loop until a certain condition is met?

南笙酒味 提交于 2019-12-10 09:46:27
问题 I'm trying to get casperjs working with the following situation: A web page loads, then within that page, it ajax loads data items along with a 'read more' button which in turn loads some more data items. I need the script to recursively check if the 'read more' button exists (as there are many data items to load), if so, click it, else continue with the rest of the script and output the full page as a jpeg. I've tried by writing the code below, but it doesn't loop as I had hoped. It just

Setting paperSize for PDF printing in Casper

…衆ロ難τιáo~ 提交于 2019-12-10 02:43:36
问题 In generating PDFs in Phantom, I can set the paper size like this: page.paperSize = { height: '8.5in', width: '11in', orientation: 'landscape', border: '0.4in' }; then the page.render(output) function generates a PDF properly. In other words, the size is correct and it has many pages of that size. I can't get this to work in Casper (and I'm not sure if it is supported). So for example, the following: var casper = require('casper').create({ paperSize: { height: '8.5in', width: '11in',

How to use NodeJS / PhantomJS / CasperJS on Windows 7

夙愿已清 提交于 2019-12-09 23:42:44
问题 I need to scrape a website form (on-the-fly) which has AJAX and SESSIONS. I did a lot of research and I came across several possible solutions one being Python::Mechanize. I don't know python and cURL alone for PHP (from my understanding) cannot handle AJAX or submit forms. I found what i believe is the possible stack which can lead me to grace :). Problem is that I do not know how to use these packages at all. I downloaded and installed NODEjs and I can call it from cmd. (great) I downloaded

CasperJs clicking links in a nested loop

谁说我不能喝 提交于 2019-12-09 23:23:41
问题 I'm trying to use PhantomJS/CasperJS to scrape a webpage. I've spent the last few days reading the docs, and searching online, but I'm stuck. The page I'm scraping shows three levels of links - years, months, and days. When you select a Year, Month, and day, a count appears in the #count div. Also, the months are actually inputs that change an image in the #imageLoad div (which I don't need). <div id="years"> <span class="year">2010</span> <span class="year">2011</span> <span class="year"

Phantomjs equivalent of browser's “Save Page As… Webpage, complete”

拟墨画扇 提交于 2019-12-09 23:19:57
问题 For my application I need to programmatically save a copy of a webpage HTML along with the images and resources needed to render it. Browsers have this functionality in their Save page as... Webpage, complete options. It is of course easy to save the rendered HTML of a page using phantomjs or casperjs. However, I have not seen any examples of combining this with downloading the associated images, and doing the needed DOM changes to use the downloaded images. Given that this functionality

Click all anchor tags on page with given class, but cancel prior to navigation

纵饮孤独 提交于 2019-12-09 23:14:57
问题 Trying to automate some testing for some analytics tracking code, and I'm running into issues when I try passing links into the each() method. I copied a lot of this from stackoverflow - how to follow all links in casperjs, but I don't need return the href of the link; I need to return the link itself (so I can click it). I keep getting this error: each() only works with arrays. Am I not returning an array? UPDATE: For each anchor tag that has .myClass, click it, then return requested

How to get the response after a POST request in CasperJS

笑着哭i 提交于 2019-12-09 20:55:34
问题 I have this very simple code to read the response from a server endpoint after a post request. Actually I'm saving a data to a database and wait for a response before going to next step casper.open('http://example.com/ajax.php, { method: 'POST', data: { 'title': '<title>', 'unique_id': '<unique_id>' } }); on ajax.php file I'm trying to echo the POST request in a simple way. this will let me know easily if I'm getting the right response from the server. echo json_encode($_POST); I tried these

Cannot navigate with casperjs evaluate and __doPostBack function

流过昼夜 提交于 2019-12-09 19:14:24
问题 When I try to navigate the pagination on sites with links where href is a __doPostBack function call, I never achieve the page change. I am not sure what I am missing, so after a few hours of messing around I decided to see if someone here can give me a clue. This is my code (uber-simplified to show the use case). var casper = require('casper').create({ verbose: true, logLevel: "debug" }); casper.start('http://www.gallito.com.uy/inmuebles/venta'); // here i simulate the click on a link in the

CasperJs loads json data from a local file

荒凉一梦 提交于 2019-12-09 08:51:13
问题 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() ... 回答1: 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" 回答2: 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.

Unsafe javascript attempt to access frame when installing casperjs through npm windows

筅森魡賤 提交于 2019-12-09 03:15:45
问题 I have installed casperjs and phantomjs on my windows machina via npm. However I get this issue. C:\>casperjs sample.js C:\>Unable to open file: sample.js Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///C:/Users/vini/AppData/Roaming/npm/node_modules/casperjs/bin/bootstrap.js. Domains, protocols and ports must match. 回答1: This is a known issue with CasperJS and the 1.9.8 version of PhantomJS. It doesn't do anything and the errors are only printed