最佳答案
根据Redirection and History - Requests documentation :
Requests will automatically perform location redirection for all verbs except HEAD.
因此,您无需担心重定向。
<小时/>问题在于USPS.COM检查User-Agent
header 并根据 header 值返回不同的结果。您需要指定 header 才能获得与浏览器相同的结果。
例如:
import requests
url = 'http://.....'
r = requests.get(url, headers={'User-Agent': 'Mozilla/5.0'})
assert 'Delivered' in r.content
关于python - 如何通过请求库获取重定向的 URL 或其内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22113738/