Created
July 1, 2013 01:32
-
-
Save eugenioclrc/5897823 to your computer and use it in GitHub Desktop.
Tweet using phantomJS
This file contains 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
/** | |
* @eugenioclrc, dedicado a Mariano "nosepuedemantener" S | |
* sudo apt-get install python g++ make | |
* sudo add-apt-repository ppa:chris-lea/node.js | |
* sudo apt-get update | |
* sudo apt-get install nodejs | |
* sudo npm install phantomjs | |
* ## Cuidado con el siguiente ln ! por ahi tenes que reescribirlo dependiendo de tu path | |
* ln -s ~/node_modules/phantomjs/lib/phantom/bin/phantomjs /usr/sbin/phantomjs | |
*/ | |
var page = require('webpage').create({ | |
userAgent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/28.0.1500.52 Chrome/28.0.1500.52 Safari/537.36", | |
webSecurityEnabled:false, | |
loadImages:false | |
}); | |
// Login | |
page.open("http://mobile.twitter.com/session/new?force=1", function(status) { | |
if ( status === "success" ) { | |
page.evaluate(function() { | |
document.querySelector("input[name='username']").value = "eugenioclrc"; | |
document.querySelector("input[name='password']").value = "123456?nop"; | |
document.querySelector("input[name='commit']").click(); | |
}) | |
page.onLoadFinished=tweet; | |
}else{ | |
console.log('Error logueando'); | |
phantom.exit(); | |
} | |
}); | |
// tweet | |
function tweet(){ | |
page.onLoadFinished = null; | |
page.open('http://mobile.twitter.com/compose/tweet',function(status){ | |
if ( status === "success" ) { | |
page.evaluate(function() { | |
document.querySelector("textarea[name='tweet[text]']").value = "Hello World 2 from phantomJS to @msemelman"; | |
document.querySelector("input[name='commit']").click(); | |
}); | |
page.onLoadFinished = phantom.exit; | |
} else { | |
console.log('Error twiteando'); | |
phantom.exit(); | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can not post a tweet