请求。获取不返回网页

2024-04-23 12:11:05 发布

您现在位置:Python中文网/ 问答频道 /正文

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

“请求的对象在此服务器上不存在。您使用的链接可能已过期、不准确,或者服务器已被指示不让您使用它。“

任何帮助都会很好,也尝试过用urllib解析,运气不好。将链接粘贴到浏览器中似乎效果不错。你知道吗

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

Tags: 对象https服务器get站点链接粘贴错误
1条回答
网友
1楼 · 发布于 2024-04-23 12:11:05

正如@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

相关问题 更多 >