Python login script
nusrath ahmed
nusrathahmed at yahoo.com
Mon Apr 25 17:15:05 EDT 2011
I have written a python script that should log me in to a website. For the time
being I want to login to gmail.com. My script pulls up the gmail webpage but
does not input the login id and the password in the fields and does not log me
in. I assume I am missing on something in my script. Can some body have a look
as to what I am missing on.
import cookielib
import urllib
import urllib2
import httplib
if __name__ == '__main__':
urlLogin = 'http://www.gmail.com'
id = 'u2'
passw = 'p2'
fieldId = 'Email'
fieldPass = 'passwd'
cj = cookielib.CookieJar()
data = urllib.urlencode({fieldId:id, fieldPass:passw})
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)
usock = opener.open(urlLogin)
usock = opener.open(urlLogin, data)
pageSource = usock.read()
usock.close()
print(pageSource)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110425/1e5f9120/attachment.html>
More information about the Python-list
mailing list