1
지금 내 Google 계정에 로그인하고 에서 외부 라이브러리을 사용하지 않고 파일을 다운로드하려고했습니다. 구체적으로 Google Finance (https://www.google.com/finance)에 대해 이야기하고 있습니다. 로그인하고 내 포트폴리오를 다운로드하면됩니다 (로그인 한 후 포트폴리오 탭으로 이동하면 스프레드 시트로 다운로드). 그러나 나는 그것을 작동시킬 수 없습니다.Python을 사용하여 Google에 로그인
비슷한 문제에 관한 여러 게시물을 보았지만 아무도 저에게 효과가 없었습니다. 내가 잘못
import urllib, urllib2, cookielib
#Gets the 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 for 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 you 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 the file
try:
urllib.urlretrieve(download_url, make_filename("My_portfolio"))
except urllib.ContentTooShortError as e:
outfile = open(make_filename("My_portfolio"), "w")
outfile.write(e.content)
outfile.close()
를하고있는 중이 야 무엇 :
이 내가 가진 코드는 지금?
감사합니다.
어떤 오류가 발생하고 있습니까? – Colleen
파일을 다운로드 중이지만 비어 있습니다. 로그인하지 않고 지정된 링크를 사용하여 포트폴리오를 다운로드하려고 할 때처럼. – user1476876
'https : // accounts.google.com/ServiceLoginAuth'에 게시하여 로그인해야합니다. URL은 로그인 페이지 일 뿐이므로 실제로 로그인 양식 제출을 시뮬레이트해야합니다. FireBug 또는 Google Dev Tools Network 패널을 사용하여 로그인 호출을하는 방법에 대해 자세히 알아보십시오. –