1、爬虫过程:
url-发送请求,获取响应-提取数据-保存-发送请求,获取响应-提取url
2、requests中解决编解码的方法:
(1)response.content.decode()
(2)response.content.decode('gbk')
(3)response.content.decode('utf-8')
(4)response.text
小练习:保存百度中的图片
【代码】
import requests #发送请求 response=requests.get("https://n.sinaimg.cn/finance/blackcat/pc/blackcat-hover.gif") #保存图片 with open("cat.png",'wb') as f: f.write(response.content)