【问题标题】:Python Requests Response 404Python 请求响应 404
【发布时间】:2021-10-01 03:13:02
【问题描述】:

我可以访问这个网站,我是从另一个网站 https://www.betexplorer.com/soccer/algeria/ligue-1/bordj-bou-arreridj-tlemcen/tfvAHu7U/ 在开发者工具的网络部分获得的。

代码

import requests

url = 'https://www.betexplorer.com/archive-odds/4urejxv464x0xd4645/18/'

response = requests.get(url, headers={'User-Agent': 'my user agent'})

print(response)

输出<Response [404]>

【问题讨论】:

  • 当我查看betexplorer.com/soccer/algeria/ligue-1/… 的所有请求时,我找不到https://www.betexplorer.com/archive-odds/4urejxv464x0xd4645/18/。是这个网站的吗?
  • 如果您尝试通过您喜欢的浏览器访问该 URL,您将获得 HTTP 404。
  • 您必须将鼠标悬停在赔率上,然后才会出现请求@AndrejKesely
  • 我添加了一张图片,显示在开发者工具中状态码是 200 @AndyKnight
  • @luka,您发送的请求与浏览器发送的请求不同。您可以添加一些您在 devtools 中看到的标头,它会通过。

标签: python web-scraping request


【解决方案1】:

设置Referer HTTP header 以获得正确的响应:

import json
import requests


url = "https://www.betexplorer.com/archive-odds/4urejxv464x0xd4645/18/"
headers = {
    "Referer": "https://www.betexplorer.com",
}
data = requests.get(url, headers=headers).json()

print(json.dumps(data, indent=4))

打印:

[
    {
        "date": "23.07. 17:36",
        "odd": "1.88",
        "change": "+0.08"
    },
    {
        "date": "23.07. 17:34",
        "odd": "1.80",
        "change": "-0.01"
    },

...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-24
    • 1970-01-01
    • 1970-01-01
    • 2020-08-04
    • 2017-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多