Skip to content

Instantly share code, notes, and snippets.

@eugenioclrc
Created July 1, 2013 01:32
Show Gist options
  • Save eugenioclrc/5897823 to your computer and use it in GitHub Desktop.
Save eugenioclrc/5897823 to your computer and use it in GitHub Desktop.
Tweet using phantomJS
/**
* @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();
}
})
}
Copy link

ghost commented Nov 9, 2016

can not post a tweet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment