如何使用请求python模块登录fidelity.com [英] How to use the requests python module to login to fidelity.com
问题描述
我正在尝试用python编写一个网络抓取程序.但是,我要抓取的页面位于登录名后面.我有一个帐户,一直在尝试遵循
I am trying to write a webscraping program in python. Howevere, the pages I want to scrape are behind a login. I have an account and have been trying to follow the help posted here . I think I have done everything right, but I cannot get past the login. My code is posted below:
#!/usr/bin/env python
import requests, sys, lxml.html
#logging in
s = requests.Session()
login_url = 'https://login.fidelity.com/ftgw/Fas/Fidelity/RtlCust/Login/'
payload = {
'ssn' : 'USERNAME',
'pin' : 'PASSWORD'
}
s.post(login_url, data=payload, headers=dict(referer='https://login.fidelity.com'))
#page to scrape
response = s.get('https://fixedincome.fidelity.com/ftgw/fi/FIBondDetails?requestType=&displayFormat=TABLE&cusip=30382LDK1&ordersystem=TORD&preferenceName=')
print response.content #redirected to the login page
推荐答案
您缺少一些东西.
登录网址为
login_url =' https://login.fidelity.com/ftgw/Fas/Fidelity/RtlCust/Login/Response/dj.chf.ra '
login_url = 'https://login.fidelity.com/ftgw/Fas/Fidelity/RtlCust/Login/Response/dj.chf.ra'
您需要在帖子中传递这两个附加参数
And you need to pass these two additional params in the post
'DEVICE_PRINT':'version%3D3.4.2.0_1%26pm_fpua%3Dmozilla%2F5.0 +(x11%3B + linux + x86_64%3B + rv%3A41.0)+ gecko%2F20100101 + firefox%2F41. 0%7C5.0 +(X11)%7CLinux + x86_64%', 'SavedIdInd':'N',
'DEVICE_PRINT' : 'version%3D3.4.2.0_1%26pm_fpua%3Dmozilla%2F5.0+(x11%3B+linux+x86_64%3B+rv%3A41.0)+gecko%2F20100101+firefox%2F41.0%7C5.0+(X11)%7CLinux+x86_64%', 'SavedIdInd' : 'N',
及其SSN和PIN(大写)
And its SSN and PIN (upper case)
此后,我尝试使用此网址,它对我有用.
I tried this url after that and it works for me.
response = s.get(' https://oltx.fidelity.com/ftgw/fbc/oftop/portfolio ')
response = s.get('https://oltx.fidelity.com/ftgw/fbc/oftop/portfolio')
打印response.content
print response.content
这篇关于如何使用请求python模块登录fidelity.com的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!