python - 如何使用请求模块检测站点检查何时重定向到另一个页面?

标签 python httplib python-requests

例如,如果我访问 www.yahoo.com/thispage,yahoo 设置了一个过滤器将 /thispage 重定向到 /thatpage。因此,无论何时有人访问 /thispage,他们都会登陆 /thatpage

如果我使用httplib/requests/urllib,它会知道有重定向吗?什么错误页面? 一些网站在找不到页面时将用户重定向到 /errorpage

最佳答案

使用 requests,您可以在响应对象的 .history 属性中获得所有重定向的列表。它返回一个 Python 列表。查看documentation了解更多。

关于python - 如何使用请求模块检测站点检查何时重定向到另一个页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13482777/

相关文章:

python - 为什么我需要部署一个 "default"应用程序才能在 GAE 中部署多个服务?

python - 循环计数器表现异常

python - 类型错误 : function() takes exactly 2 arguments (1 given) (python)

python - 错误 : can't start new thread

python - 来自其他 IP 而不是本地主机的请求在长时间等待时没有响应

python - 不可散列类型 : 'dict' while applying a function with pandas?

python - numexpr 支持特殊的贝塞尔函数吗?

Python脚本可以在不下载整个页面的情况下查看网页是否存在?

Python httplib.HTTPS连接和密码

python - 即使使用 requests.history,从重定向 2 次的 URL 下载 pdf 文件也会失败