我正在尝试用 python 编写一个网页抓取程序。然而,我想要抓取的页面是在登录后面的。我有一个帐户,并一直在尝试遵循发布的帮助 here 。我认为我已经做对了一切,但我无法通过登录。我的代码发布如下:
#!/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
最佳答案
你错过了一些东西。
登录网址是
登录网址='https://login.fidelity.com/ftgw/Fas/Fidelity/RtlCust/Login/Response/dj.chf.ra '
并且您需要在帖子中传递这两个附加参数
'DEVICE_PRINT':'版本%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(大写)
之后我尝试了这个网址,它对我有用。
响应 = s.get(' https://oltx.fidelity.com/ftgw/fbc/oftop/portfolio ')
打印响应内容
关于python - 如何使用 requests python 模块登录 fidelity.com,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45084888/