使用python的请求库发出get请求

时间:2020-11-12 18:20:44

标签: python-requests postman

我必须在https://isbnsearch.org/处获取请求,以从给定的isbn号中获取图书详细信息。 查询网址看起来像这样

https://isbnsearch.org/isbn/<ISBN number>

当我从POSTMAN发出get请求时,事情按需要工作。.但不适用于请求。 我的代码看起来像这样

url = 'https://isbnsearch.org/isbn/9788170289265'
requests.get(url)

它的状态码为403。如果禁止“请求”使用,为什么不要求邮递员使用?

1 个答案:

答案 0 :(得分:1)

您请求的网站似乎不支持默认的python请求User-Agent,即python-requests/2.25.0或您使用的任何版本。更改User-Agent似乎可行:

import  requests

url = "https://isbnsearch.org/isbn/9788170289265"
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64;"}
r = requests.get(url, headers=headers)