----------
------------------------------------------------------------------------------------------------------------------------------------------------
-豆瓣有反爬。加入headers(请求头)
import urllib.request url='https://movie.douban.com/' headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.100 Safari/537.36'} #构建请求对象 req=urllib.request.Request(url,headers=headers) #使用urlopen打开请求 resp=urllib.request.urlopen(req) #从响应结果中读取数据 html=resp.read().decode('utf-8') print(html)
标签:请求,request,req,Request,urllib,发送,headers,3.3 From: https://www.cnblogs.com/988MQ/p/17044908.html