【发布时间】:2019-12-17 01:12:07
【问题描述】:
我想用 Python 打开一个网站的链接,流程如下:
我打开主 URL(例如 www.url1.com)
我抓取页面并找到按钮,它有一个重定向链接(www.url2.com)
当我在浏览器中使用此链接时,它会重定向到 (www.url3.com) 然后立即转到另一个(必填链接)(www.url4.com)
当我使用 Python 请求尝试相同的流程时,它只会转到 (www.url3.com)
我尝试使用
allow_redirects参数没有任何成功
这是我的代码:
import requests
headers = {
'User-Agent': '',
'authority': '',
'scheme': '',
'accept': '',
'x-requested-with': '',
'cookie': '',
'referer':
}
def download(req):
resp = requests.get(req, headers=headers, allow_redirects=True)
print(resp.text)
我还尝试使用此answer 打印历史记录。
但它也一直在重定向我 (url3)
【问题讨论】:
-
如果 url3 使用
refresh meta tag重定向浏览器,requests将不会跟随它,即使启用了allow_redirects,因为它不解析 html。 How to follow meta refresh in python
标签: python http python-requests