01 requests基本使用

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)

猜你喜欢

转载自www.cnblogs.com/urassya/p/11093865.html
今日推荐