Login to google using Python -
i have been trying time login google account , download file without using external libraries. talking google finance (https://www.google.com/finance). want login, , download portfolio (after sign in , go portfolios tab, there link saying: download spreadsheet). can't work.
i have seen several posts here regarding similar problems none of them worked me.
this code have now:
import urllib, urllib2, cookielib #gets current directory output_path = os.getcwd() def make_url(ticker_symbol): return base_url + ticker_symbol def make_filename(ticker_symbol): return output_path + "\\" + ticker_symbol + ".csv" # login page google finance login_url = "https://accounts.google.com/servicelogin?service=finance&passive=1209600&continue=https://www.google.com/finance&followup=https://www.google.com/finance" # google finance portfolio download url (works after signed in) download_url = "https://www.google.com/finance/portfolio?pid=1&output=csv&action=viewt&ei=ypzyuzi_eqgawap5vg" username = 'my_username' password = 'my_password' cj = cookielib.cookiejar() opener = urllib2.build_opener(urllib2.httpcookieprocessor(cj)) login_data = urllib.urlencode({'username' : username, 'j_password' : password}) opener.open(login_url, login_data) # download file try: urllib.urlretrieve(download_url, make_filename("my_portfolio")) except urllib.contenttooshorterror e: outfile = open(make_filename("my_portfolio"), "w") outfile.write(e.content) outfile.close()
what doing wrong?
thanks lot!!
the author of script mention has since updated said script(s). these scripts designed gvoice, can used example needs gfinance i'm sure.
the new scripts found @ github.
Comments
Post a Comment