【排错】Requests有headers请求get网页,解析正常。无头不正常
2019年07月09日 17:23:20 作者:Jiaozn 分类:Python 评论(0)
# -*- coding:utf-8 -*-
import time
import requests
headers={
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36'
}
response=requests.get('http://maoyan.com/board/4?offset=10',headers=headers)
html=response.text
print(response.status_code)
print(html)例如以上代码,在get方法中去掉headers,在response.text时候出现错误,加上则正常。估计是编码原因引起的。
除非注明,发表在“Jiaozn的博客”的文章『【排错】Requests有headers请求get网页,解析正常。无头不正常』版权归Jiaozn所有。
转载请注明出处为“本文转载于『Jiaozn的博客』原地址https://jiaozn.com/reed/492.html”

评论
发表评论