【发布时间】:2021-06-11 04:04:02
【问题描述】:
我正在尝试获取 https://trade.ec.europa.eu/doclib/html/153814.htm 指向的重定向 URL(一个 pdf 文件)。
我已经试过了
r = requests.get('https://trade.ec.europa.eu/doclib/html/153814.htm', allow_redirects = True)
print(r.url)
它会输出相同的旧 URL。我需要重定向的 URL,即https://trade.ec.europa.eu/doclib/docs/2015/september/tradoc_153814.pdf
【问题讨论】:
-
您可以使用 CURL 来跟踪重定向。 davidwalsh.name/curl-follow-redirects
-
希望你已经安装了包
requests。例如,在 MS-DOS 上,使用命令提示符命令<path_to_python>\python.exe -m pip install requests安装包requests。 -
这个问题已经在这个链接stackoverflow.com/questions/23146961/…得到了回答
标签: python web-scraping python-requests