从经过身份验证的URL下载包含python请求的CSV文件

2024-09-28 19:10:18 发布

您现在位置:Python中文网/ 问答频道 /正文

对于我的一个项目,我需要从一个网站认证的URL获取一个CSV文件。不幸的是,没有API来做这件事。因此,我决定使用请求和会话来获取它。在

登录页面是: http://extranet.ffbb.com/fbi/identification.do

我在页面上查看了HTML代码中的登录名和密码名。登录名是“标识bean.identifiant“密码是”标识bean.mdp". 在

因此,我尝试连接并用以下代码显示返回的HTML,但它返回的HTML代码是错误的登录/密码(就像我从浏览器输入了错误的登录/密码)。我相信我的资历是对的。在

login = "my_login"
password = "my_password"

with requests.Session() as session:
    data = {
        'identificationBean.identifiant': '{}'.format(config.login),
        'identificationBean.mdp': '{}'.format(config.password)
    }
    url = 'http://extranet.ffbb.com/fbi/identification.do'
    response = session.post(url, data=data)
    print(response.text)

谢谢你的帮助


Tags: 代码comhttp密码datahtmlloginpassword