Python请求:不允许的方法

2024-04-20 11:45:20 发布

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

我试图使用requests.get()访问thisURL,但它给出了405。通过浏览器访问时不存在此类问题。在


Tags: get浏览器requeststhisurl
2条回答

只是猜测一下,可能是因为你试图直接访问页面。在

你能试着添加一个推荐网址吗 其中my峎referer是网站主页的url

在请求.get(url,headers={'referer':我的介绍人})

我已经添加了正确的标题,试试这个

import requests

headers = {
                "Host": "www.propertyshark.com",
                "Connection": "keep-alive",
                "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36",
                "Upgrade-Insecure-Requests": "1",
                "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
                "Accept-Encoding": "gzip, deflate, br",
                "Accept-Language": "en-US,en;q=0.9",
}

url = "https://www.propertyshark.com/mason/Property/53047525/1302-Richland-Ave-Santa-Ana-CA-92703/"

req = requests.get(url, headers=headers)
print(req.status_code)

相关问题 更多 >