【发布时间】:2022-01-09 11:16:38
【问题描述】:
我正在尝试从网站下载一组报告(PDF 和 XLSX)。
我有一个有效的解决方案现在失败了,因为重要的 GET 请求现在正在响应
{'result': 'redirect', 'url': '../warning.asp?header=Report has expired&body=Your report has already expired. Please select a report from the menu.&footer='}
在 postman 中执行必要的登录、报告选择和输出步骤可以完美运行。 python下的同样是给我上面的问题。
我可以登录到实际的网站并跟踪各个步骤。我注意到一步会打开一个新的浏览器窗口,然后自动开始下载报告。
代码很简单
rw = session.get('https://website.com.au/Reports/ReportWindow.asp?' + report_urlencoded)
if rw.status_code == 200:
print('https://website.com.au/reports/generatereport.asp?_=' + str(current_milli_time()))
gr = session.get('https://website.com.au/reports/generatereport.asp?_=' + str(current_milli_time()))
线
rw = session.get('https://website.com.au/Reports/ReportWindow.asp?' + report_urlencoded)
打开一个新窗口并自动继续下载请求的报告(如果我使用实际浏览器)
以上在邮递员中的运行完全符合我的要求。
我在这里缺少什么?
谢谢
【问题讨论】:
-
一些网站避免剥离请求检查标题。尝试添加有效的标头(您可以从邮递员请求代码中复制代码以进行 python 请求)。
标签: python python-requests postman