1.urllib方法

import urllib.request#导入模块

res = urllib.request.urlopen('http://www.sina.com.cn/')#打开网页
html = res.read()#读取内容,二进制形式
html = html.decode('utf-8')#转换为utf-8
print(html)#输出

>>>type(html)
>>> str

2.requests方法

import requests#导入模块

res = requests.get('http://www.sina.com.cn/')#获得请求
res.encoding = 'utf-8'#设置编码格式
print(res.text)#以文本形式输出

>>>type(res.text)
 >>>str
>>>type(res)
>>>requests.models.Response

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-24
  • 2021-10-04
猜你喜欢
  • 2021-12-25
  • 2018-08-07
  • 2021-05-22
  • 2021-12-25
  • 2022-01-12
相关资源
相似解决方案