Created
December 10, 2015 16:32
-
-
Save agusmakmun/4aa3d1a0b261c9aea6f8 to your computer and use it in GitHub Desktop.
Just Login to Twitter using cookielib
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
import urllib, urllib2, cookielib | |
username = 'username' | |
password = 'password' | |
cj = cookielib.CookieJar() | |
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) | |
login_data = urllib.urlencode({'session[username_or_email]' : username, 'session[password]' : password}) | |
opener.open('https://twitter.com/sessions', login_data) | |
resp = opener.open('https://twitter.com/yourname') | |
op = open("out_twitter.txt", "w") | |
op.write(resp.read()) | |
op.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I'm trying to use your code to do twitter log in but haven't been successful.
I did however modify your code for Python 3.5. I'm wondering if you can provide some thoughts.
import urllib.request
import urllib.parse
import http.cookiejar
username = 'xxx'
password = 'xxx'
cj = http.cookiejar.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
login_data = urllib.parse.urlencode({'session[username_or_email]' : username, 'session[password]' : password})
login_data = login_data.encode('utf-8')
opener.open('https://twitter.com/sessions', login_data)
resp = opener.open('https://twitter.com/yourname')
print (resp.read().decode('utf-8'))