python基础day3-requests基本使用(百度一下),2019-6-25

import requests  # 导入requests请求库

# 往百度主页发送请求,获取响应对象
response = requests.get(url='https://www.baidu.com/')

# 设置字符编码为 utf-8
response.encoding = 'utf-8'

# 打印响应文本
print(response.text)

# 把响应文本写入本地
with open('baidu.html', 'w', encoding='utf-8') as f:
f.write(response.text)

posted on 2019-06-26 22:23  leyzzz  阅读(99)  评论(0编辑  收藏  举报

导航