首页 > 其他分享 >3.4 urlopen()方法的源代码

3.4 urlopen()方法的源代码

时间:2023-01-11 21:58:54浏览次数:51  
标签:urlopen resp request urllib url 3.4 opener 源代码

---

 

 

 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

'''
import  urllib.request
url='https://www.baidu.com'
resp=urllib.request.urlopen(url)
'''

import urllib.request
url='https://www.baidu.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)

#获取opener对象
opener=urllib.request.build_opener()

resp=opener.open(req)
print(resp.read().decode())

 

标签:urlopen,resp,request,urllib,url,3.4,opener,源代码
From: https://www.cnblogs.com/988MQ/p/17044986.html

相关文章