【问题标题】:requests.get not returning webpagerequests.get 不返回网页
【发布时间】:2017-08-16 09:51:46
【问题描述】:

当尝试返回以下站点时,我收到以下错误:

“请求的对象在此服务器上不存在。您访问的链接已过时、不准确,或者已指示服务器不让您拥有它。”

任何帮助都会很棒,也尝试使用 urllib 进行解析,但没有运气。将链接粘贴到浏览器中似乎可以正常工作。

r = requests.get('https://us.spdrs.com/product/fund.seam?ticker=QCAN')
print(r.text)

【问题讨论】:

  • 您应该尝试在浏览器中再次粘贴该链接,因为它不起作用。您将收到相同的 404 Not Found 消息。
  • 为我工作..
  • 好吧,那么也许该网站有一些防刮保护。
  • 它为我重定向到https://us.spdrs.com/en/etf/spdr-msci-canada-strategicfactors-etf-QCAN。如果它在 Python 中不起作用,但在浏览器中起作用,则可能有一些反刮擦措施。查找如何伪造标头,特别是用户代理,作为规避的第一步。也就是说,我是根据请求完成的,它对我有用(曾经,你在敲它吗?)。
  • 是的,链接对我来说效果很好,我没有在几分钟内敲击它,但确实击中了 5-6 次。我会在不同的 IP 下尝试感谢反馈的家伙

标签: python python-requests


【解决方案1】:

正如@CuriousGeorge 所怀疑的,结果因源IP 而异:

import requests
response = requests.get('https://us.spdrs.com/product/fund.seam?ticker=QCAN')
for r in response.history:
    print(r.status_code, r.url)
print(response.url)

美国:

301 https://us.spdrs.com/product/fund.seam?ticker=QCAN
301 https://us.spdrs.com/en/product/fund.seam?ticker=QCAN
301 https://us.spdrs.com/product/fund.seam?ticker=QCAN
301 https://us.spdrs.com/en/product/fund.seam?ticker=QCAN
301 https://us.spdrs.com/etf/spdr-msci-canada-strategicfactors-etf-QCAN
https://us.spdrs.com/en/etf/spdr-msci-canada-strategicfactors-etf-QCAN

法国:

301 https://us.spdrs.com/product/fund.seam?ticker=QCAN
302 https://fr.spdrs.com/fr/product/fund.seam?ticker=QCAN
301 https://fr.spdrs.com/product/fund.seam?ticker=QCAN
302 https://fr.spdrs.com/fr/product/fund.seam?ticker=QCAN
301 https://fr.spdrs.com/product/index.seam?cid=0
https://fr.spdrs.com/fr/product/index.seam?cid=0

加拿大:

301 https://us.spdrs.com/product/fund.seam?ticker=QCAN
https://global.spdrs.com/product/fund.seam?ticker=QCAN

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-06
    • 2016-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多