Request标准库-学习笔记01

上一篇 / 下一篇  2019-11-06 11:54:08 / 个人分类:Request标准库

爬虫过程:

url-发送请求,获取响应-提取数据-保存-发送请求,获取响应-提取url

 

requests中解决编解码的方法:

response.content.decode()

response.content.decode('gbk')

response.content.decode('utf-8')

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)


TAG:

 

评分:0

我来说两句

日历

« 2024-04-16  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 1119
  • 日志数: 1
  • 建立时间: 2018-11-28
  • 更新时间: 2019-11-06

RSS订阅

Open Toolbar