最近,我正在学习python。当我使用BeautifulSoup并请求获取html时,我的状态是405。另外,汤是错误的。我访问了URL。python网络爬虫,当我抓取一个URL时,status_code显示405
这里是我的代码:
def craw(url):
user_agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0'
headers = {'User_Agent':user_agent,
'Accept':'*/*',
'Accept-Encoding':'gzip, deflate',
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language':'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
'Host':'www.qichacha.com',
'Referer':'http://www.qichacha.com/search?key=%E5%A9%9A%E5%BA%86',
}
response = requests.get(url,headers = headers)
if response.status_code != 200:
response.encoding =