基本介绍
requests是一个能够模拟浏览器上网的模块。
环境安装
pip install requests
流程
指定url
url = '网址'
发送请求
#请求方式根据浏览器的请求来,这里假设是用Get
response = requests.get(url)
#设置响应对象的编码格式(处理中文乱码)
response.encoding = 'utf-8'
3.获取响应数据
page_text = response.text #text是可以返回字符串形式的响应数据/爬取到的数据
4.持久化存储
with open('dongfang.html','w') as fp:
fp.write(page_text)