python - 如何使用 requests python 模块登录 fidelity.com

标签 python authentication web-scraping python-requests

我正在尝试用 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/

相关文章:

python - Python 统计事件数量

asp.net - 如何注销多个 asp.net 应用程序?

jquery ajax 调用 asp.net mvc 应用程序获得两个未经授权的响应,然后确定

python - 请求在表单上发布不返回生成的页面

node.js - 抓取 Netflix

python - 执行 python manage.py runserver 时 cmp 错误超出最大递归深度

python - 您可以获得 Google Cloud Composer/Airflow 的静态外部 IP 地址吗?

python - 用Python计算多项式?

php - Symfony 安全返回 401 响应而不是重定向

python - 让 Scrapy 只抓取后代链接