【问题标题】:Python requests.get(URL) returns 404 error when using URL with dotPython requests.get(URL) 在使用带点的 URL 时返回 404 错误
【发布时间】:2022-01-13 08:37:07
【问题描述】:

我正在尝试使用 Python 的 Requests 库获取网页 https://finance.yahoo.com/quote/AFLT.ME

此链接在浏览器中打开良好,但在使用此代码时导致错误 404:

import requests
r = requests.get('https://finance.yahoo.com/quote/AFLT.ME')

我很确定问题出在“AFLT.ME”中的点 (.) 符号中,因为代码适用于不带点的 URL - 例如 https://finance.yahoo.com/quote/AAPL

我已经找到了解决这个问题的答案,但是在网站所有者方面。

但是我该如何解决这个问题呢?

我尝试了一些建议,但不幸的是没有帮助:

  • 将点 . 替换为 %2f,例如 /AFLT%2EME
  • 在末尾添加斜线/,如/AFLT.ME/

【问题讨论】:

    标签: python html url get http-status-code-404


    【解决方案1】:

    奇怪,如果发送User-Agent 标头,即使是空值,它也会以 200 响应:

    >>> requests.get('https://finance.yahoo.com/quote/AFLT.ME', headers={'User-Agent': ''})
    <Response [200]>
    

    编辑:这里报告了同样的问题:https://stackoverflow.com/a/68259438/9835872

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-15
      • 2021-08-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多