Automatic Web logon

Sakis Kasampallis | May 21, 2011 | 1 min read

Visiting Yahoo! Answers without using a Web browser 

I believe that services like Yahoo! Answers are very useful and use them at times. The Yahoo! Answers community gives an extra point to users each time they visit their account (but only once/day).

The problem is that usually I'm very busy (or lazy) and thus I always forget to visit my account. Therefore I was looking for ways of automating the process. It looks like this is very straightforward to do when the right tools are used. Here's a quick solution using Python:

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
view raw answers.py hosted with ❤ by GitHub
You might argue that using clear-text passwords is not a good practice; that is absolutely right, but in this case I'm not insane about the protection of my Yahoo! credentials since Answers is the only Yahoo! service that I use.

Happy coding!