My python script dosen't open the browser and auto log in
I have written a python script to auto login in开发者_如何转开发to a website every time I click on it. The script runs fine on the command prompt but does not open the browser. I can see the html source code run in the command prompt but it doesn't open the browser. I have not included any browser based command also, may be thats one reason but I have no idea how to include the browser command eg:webbrowser.open because when I include this command it simple opens the browser but does not log me in. I guess there is a timing issue. Can somebody correct my script for auto login.
import cookielib
import urllib
import urllib2
if __name__ == '__main__':
urlLogin = 'http://www.gmail.com'
id = 'my.email'
passw = 'my.password'
fieldId = 'email'
fieldPass = 'pass'
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)
usock = opener.open('http://www.gmail.com')
pageSource = usock.read()
usock.close()
print(pageSource)
Thanks, that would be a great help
AFAIK, urllib has no relationship with your browser. Instead, Python is successfully connecting itself to the remote system, logging in, and retrieving the resulting page.
You probably want webbrowser, not urllib. The documentation for that module is here: http://docs.python.org/library/webbrowser.html
精彩评论