我正在尝试从this网站获取scarp信息,但一直获取状态代码:403, 所以尝试使用header,但是得到了TypeError:request()得到了一个意外的关键字参数“header”
代码:
import requests
head = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0'}
url = "https://www.accuweather.com/en/bd/dhaka/28143/current-weather/28143"
pageObj = requests.get(url, header = head)
print("Status code: " + str(pageObj.status_code)) # *for testing purpose*
错误:
^{pr2}$我做错什么了?在
参数的名称是
headers
,而不是header
。参见docs。在使用
pageObj = requests.get(url, headers=head)
您需要在
params
中设置header
:相关问题 更多 >
编程相关推荐