Myspace auto login using Python
Today I am going to share with you an interesting program - a Python script that logs in to myspace given your username (email address) and password. If you study the script, you will get idea about the following things:
And check this link to get idea, how do I know details about request header and post values!
- HTTP POST in Python
- How to use cookiejar
- How to add user-agent, referer etc. to the request header using Python
- And of course, how to auto login to a site :)
import urllib2, cookielib, re
url = 'http://secure.myspace.com/index.cfm?fuseaction=login.process'
email = "" #put your email address here
pwd = "" #put your password here
data = "__VIEWSTATE=%2FwEPDwUKLTY1Mjc2MTMwMWQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgIFPWN0bDAwJGN0bDAwJE1haW4kY3BNYWluJFNwbGFzaERpc3BsYXkkY3RsMDAkUmVtZW1iZXJfQ2hlY2tib3gFPWN0bDAwJGN0bDAwJE1haW4kY3BNYWluJFNwbGFzaERpc3BsYXkkY3RsMDAkTG9naW5fSW1hZ2VCdXR0b24%3D&NextPage=&ctl00%24ctl00%24Main%24cpMain%24SplashDisplay%24ctl00%24Email_Textbox="+email+"&ctl00%24ctl00%24Main%24cpMain%24SplashDisplay%24ctl00%24Password_Textbox="+pwd+"&ctl00%24ctl00%24Main%24cpMain%24SplashDisplay%24ctl00%24Login_ImageButton.x=36&ctl00%24ctl00%24Main%24cpMain%24SplashDisplay%24ctl00%24Login_ImageButton.y=15&ctl00%24ctl00%24Main%24cpMain%24SplashDisplay%24ctl00%24nexturl=&ctl00%24ctl00%24Main%24cpMain%24SplashDisplay%24ctl00%24apikey=&ctl00%24ctl00%24Main%24cpMain%24SplashDisplay%24ctl00%24ContainerPage="
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
opener.addheaders = [('Referer', 'http://www.myspace.com/index.cfm?fuseaction=splash'),
('Content-Type', 'application/x-www-form-urlencoded'),
('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14')]
usock = opener.open(url, data)
the_page = usock.read()
usock.close()
And check this link to get idea, how do I know details about request header and post values!
Comments
By the way, have you checked out this year's Google Treasure Hunt? I found the answers using Python. If you're interested, you're welcome to check out my blog post about it :)
also, can you explain where you got the data field which you send along with the url? thanks!
me@benhammondmusic.com
You should have a look to this list of 50 useful python modules.
Keep up the good work!
There is something strange in your script, I don't understand how are the email and password variable being sent to the server. I thought they needed to be encoded and sent with the header or something like that.
When i examine the text i get back from the usock.read() it is just the front page of myspace, which could be read w/o logging in.
This explains how to make scripts like these
http://linux-junky.blogspot.com/2010/03/python-script-for-sending-free-sms-in.html