Data, Maps, Usability, and Performance

API canvas d3 data geo GeoJSON html5 image JavaScript json maps mysql PHP WordPress

Results for tag: casperjs

Automate Pinterest Pinning with CasperJS

Auto Pin on Pinterest Script

How do you pin photos on Pinterest automatically? I have covered some elements of the Pinterest API before, but I did not expose the endpoints necessary to pin via the API. None of that is yet publicly available but it got me thinking about doing more programmatically on Pinterest in general. What would it take to automate the process of pinning an image automatically? I think a simple solution is to use a headless browser and recreate the steps to make that happen. Lets go over a simple script that will login into Pinterest, retrieve an image from an external source, add pin it to a board with a pin description.
Read more

Making Maps from CIA World Factbook

World Population Map for 2013

D3 World Map with Country Information
2013 World Population Map
2013 World Population Density Choropleth Map

The CIA world factbook is a great resource for information about various countries and territories. It can and it has been used often to create world maps for specific data points. The problem is that a lot of the data changes frequently and retrieving this content is not straightforward. The pages are not well formed and the data is not delivered in JSON or CSV formats. Instead, these great country metrics are just dumped into the content of the page and even thought the pages are nice and readable, the source is painful to scrape.
Read more

Grabbing HTML source code with PhantomJS or CasperJS

CasperJS Evaluate source code

Have you ever tried to retrieve the source code of a page with PhantomJS or CasperJS? Sure, there is a method in the API to save the source to a file but what if you wanted to work with it inside your script? One way to approach this would be to work on the DOM with the page evaluate method. After all, you can retrieve the source code of any page from the DOM by finding the HTML object. Here’s how to do it with PhantomJS or CasperJS.
Read more

Simple installation of NodeJS, PhantomJS, and CasperJS

CasperJS version

I have mentioned using CasperJS for screenshots previously, the awesome navigation scripting and testing utility for PhantomJS (headless webkit browser for NodeJS), but I wanted to cover something that can be a bit painful at times: installation. You can install all three of these on your MAC or Windows OS but I would recommend grabbing a free VM via VirtualBox, loading Ubuntu on it, and doing it in Linux. It’s actually a really simple approach and you will be working in a separate environment.
Read more

Viewing and Disabling Cookies in CasperJS and PhantomJS

browser cookies

Today, I have once again been messing around with CasperJS and this time around, I wanted to play around with browser cookies. PhantomJS API Reference has a command line option –cookies-file=/path/to/cookies.txt that specifies the file name to store persistent cookies but I want to disable cookies, not store them. I also want to test and see what the cookies are on the page to verify that they have been disabled.
Read more

Using CasperJS to Make MultiBrowser Screenshots

render screenshots in casperjs

Update: As pointed out in the comments, we are only changing a user-agent string not the rendering engine. IE Conditional comments are enabled through the IE rendering engine so sending an IE user-agent will not give you a real IE screenshot. With that being said, you can use SlimmerJS to render Gecko (browser engine of Mozilla Firefox) screenshots instead of WebKit.

CasperJS is an awesome testing utility for PhantomJS, a headless WebKit browser. In other words, it is something like Selenium, a tool for you to automate a browser, but written in JavaScript instead of Java. It basically allows you to run all kinds of tests on your website and log the information or render screenshots. It comes packaged with a sample script for making a screenshot, but what if you wanted to make a couple screenshots per page based on different browsers (different user agent string).

Well, if you look at the CasperJS API you can see a userAgent example but this example does not work. It is not very obvious at first as the example seems to be working when run (you get the expected print statements in the console). However, if you include a callback on resource requested and retrieve the User-Agent string for each resource, you quickly realize that both tests have been done with the same last user agent string. Look at the output of this example code:
Read more