使用Python Requests爬取aiscore.com API时遭遇403错误的解决方法咨询
使用Python Requests爬取aiscore.com API时遭遇403错误的解决方法咨询
我在 aiscore.com 上通过Network - Fetch/XHR工具找到了一个API请求地址,具体是:https://api.aiscore.com/v1/web/api/match/mlive?lang=8&match_id=zrkn6ivlz58cwql&country_code=IT
但当我尝试用Python Requests库爬取这个接口的数据时,始终收到403错误。以下是我编写的完整代码:
import requests url = "https://api.aiscore.com/v1/web/api/match/mlive?lang=8&match_id=zrkn6ivlz58cwql&country_code=IT" headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" } response = requests.get(url, headers=headers) if response.status_code == 200: data = response.json() print(data) # 打印数据 else: print(f"Errors: {response.status_code}")
我已经在请求头中添加了常见的Chrome浏览器User-Agent,但还是无法成功获取数据。有没有什么可行的方法可以解决这个403错误,顺利爬取到目标接口的数据呢?
备注:内容来源于stack exchange,提问作者Mapi




