请求登录并忽略弹出窗口

时间:2019-01-21 10:25:29

标签: python python-requests

以下是我从网站下载文件的抓取代码。 在网站上进行了一些近期更改之后,我的提取内容失败,未登录错误。我意识到,如果我使用CSRF令牌执行get请求,则可以下载文件(没有登录错误)。

import requests
session     = requests.Session()
payload     = {'user':'*****','pword':'*****'}
logIn       = session.post('https://sftp.mcxindia.com/Web%20Client/Login.xml?Command=Login&Sync=StayHungryStayFoolish', data=payload,verify=False)
#fetch       = session.get('https://sftp.mcxindia.com/?Command=Download&File=%2FCommon%2FContract%20Master%2FCTCLContractMaster%2FMCXScrips.bcp') #gives login error
fetch       = session.get('https://sftp.mcxindia.com/?Command=Download&File=%2FCommon%2FContract%20Master%2FCTCLContractMaster%2FMCXScrips.bcp&CsrfToken=SOME_TEXT_I_GET_FROM_logIn.text')

要下载的Web版本运行正常,这表示有效负载正确。 有没有更好的方法来使用CsrfToken。目前,我正在从logIn.text的xml中获取它

0 个答案:

没有答案