Created
December 1, 2015 04:14
-
-
Save icaromh/ad939d101b0ffc83dd54 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Nightmare = require('nightmare') | |
, vo = require('vo') | |
, fs = require('fs') | |
, request = require('request') | |
, account = require('./account.js') | |
, username = account.username | |
, password = account.password | |
; | |
vo(run)(function(err, result) { | |
if (err) throw err; | |
}); | |
function *run() { | |
var x = Date.now(); | |
var nightmare = Nightmare({ show: true }); | |
var src = yield nightmare | |
.useragent('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36') | |
.goto('https://www.instagram.com/accounts/login/') | |
.wait() | |
.wait('.-cx-PRIVATE-SlimLoginForm__button') | |
.evaluate(function(username, password){ | |
var event = new Event('input', { bubbles: true }); | |
$('[name=username]')[0].value = username; | |
$('[name=username]')[0].dispatchEvent(event); | |
$('[name=password]')[0].value = password; | |
$('[name=password]')[0].dispatchEvent(event); | |
}, username, password) | |
.wait(600) | |
.click('.-cx-PRIVATE-SlimLoginForm__button') | |
.wait(600) | |
.goto('https://instagram.com/marciegottschalk/') | |
.wait() | |
.click('.-cx-PRIVATE-Photo__clickShield') // clica na primeira foto | |
.wait().wait(1000) | |
.screenshot('before.png') | |
.evaluate(function(){ | |
$('.-cx-PRIVATE-PostInfo__likeButton.coreSpriteHeartOpen')[0].click(); | |
}) | |
.wait(1000) | |
.screenshot('after.png') | |
.evaluate(function(){ | |
var liked = document.querySelectorAll('.-cx-PRIVATE-PostInfo__likeButton.coreSpriteHeartFull').length; | |
if(liked === 0){ | |
return document.querySelector('.-cx-PRIVATE-Photo__image').src; | |
} | |
}); | |
console.log("done in " + (Date.now()-x) + "ms"); | |
if(src) | |
downloadImage(src); | |
yield nightmare.end(); | |
} | |
function downloadImage(src){ | |
request({ url: src, encoding: 'binary'}, function(err, res, body){ | |
fs.writeFile('./foto.png', body, 'binary', function(err){ | |
if(!err) console.log('foto salva :)') | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment