Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@techslides
Created April 22, 2015 18:14
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save techslides/3e207f0f7846c9b6d682 to your computer and use it in GitHub Desktop.
Save techslides/3e207f0f7846c9b6d682 to your computer and use it in GitHub Desktop.
Pinterest Pin Image Script
var casper = require('casper').create({
verbose: true,
logLevel: 'debug',
pageSettings: {
loadImages: true,
loadPlugins: true,
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'
}
});
//casper.options.waitTimeout = 10000;
//PhantomJS comes with a default viewport size of 400x300, and CasperJS doesn’t override it by default.
//casper.options.viewportSize = {width: 1600, height: 950};
casper.options.viewportSize = {width: 500, height: 400};
//debug
/*
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.on('resource.received', function(resource) {
casper.echo(resource.url);
});
//abort example
casper.on('page.resource.requested', function(requestData, request) {
if (requestData.url.indexOf('http://adserver.com') === 0) {
request.abort();
}
});
//get all info example with JSON.stringify
casper.on('resource.requested', function(resource) {
casper.echo(JSON.stringify(requestData));
});
*/
//lets login into Pinterest
var url = 'https://www.pinterest.com/login/';
casper.start(url, function() {
this.fill('form.loginForm', {
username_or_email: 'YOUR EMAIL',
password: 'YOUR PASSWORD'
}, true);
});
//External image pinnned to board
var imageurl = encodeURIComponent("http://techslides.com/demos/samples/sample.jpg"); //works here
var pinurl = "https://www.pinterest.com/pin/find/?url="+imageurl;
casper.thenOpen(pinurl, function() {
//debug progress
//this.capture('pinterest0.png');
this.click(".repinSendButtonWrapper button");
this.wait(2000, function() {
//debug progress
//this.capture('pinterest1.png');
this.click(".BoardPickerDropdownButton");
this.wait(2000, function() {
//debug progress
//this.capture('pinterest2.png');
//specify board via nth-child selector
this.click(".SelectList ul li:nth-child(7)");
//fill description and submit
this.fill('form.standardForm', {
'description':'YOUR DESCRIPTION'
}, true);
});
});
});
casper.then(function() {
this.wait(5000, function() {
this.capture('pinterest-final.png');
});
});
casper.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment