Skip to content

Instantly share code, notes, and snippets.

@faif
Created January 5, 2012 20:16
Show Gist options
  • Save faif/1567050 to your computer and use it in GitHub Desktop.
Save faif/1567050 to your computer and use it in GitHub Desktop.
Web logon
import urllib.request, urllib.parse
MAX_TRIES = 3
if __name__ == '__main__':
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor())
urllib.request.install_opener(opener)
params = urllib.parse.urlencode(dict(login='username@yahoo.com',
passwd='y0uRpas5'))
utf_params = params.encode('utf-8')
login_success = False
cur_try = 0
while not login_success and MAX_TRIES != cur_try:
try:
opener.open('https://login.yahoo.com', utf_params)
url = opener.open('http://answers.yahoo.com')
content = url.read().decode('utf-8')
# print(content)
login_success = True
except Exception as e:
print(e)
cur_try += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment