【问题标题】:Handling redirections in python在 python 中处理重定向
【发布时间】:2020-04-09 03:03:48
【问题描述】:

我有一个类似于http://www.example.com/link?url=http://www.google.com 的网址。当在浏览器中打开时,URL 会重定向到 http://www.google.com。但是当我检查 URL 的状态码时,它显示的是 200 而不是 3xx。即使我检查print(url.history),它也会显示[]。请解释!

编辑:我检查了请求的响应:

var url = 'http://www.google.com';
window.location=url;
</script>
<!-- Form pop up box -->
    <div id="popUpPageConatiner" style="display:none;" ></div>
<!-- close form pop up box -->

【问题讨论】:

标签: python python-3.x url redirect python-requests


【解决方案1】:

requests.get 默认以{'allow_redirects': True} 运行,这意味着您将有response.status_code 输出200,而不是302301

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-13
    • 2015-06-10
    • 2017-06-12
    • 2010-10-18
    • 1970-01-01
    相关资源
    最近更新 更多