Python简单案例1

案例1:

 

# coding=utf-8

import requests
# 以get方法发送请求,返回数据
response = requests.get('http://www.baidu.com')
# 以二进制写入的方式打开一个文件
f = open('index.html', 'wb')
# 将响应的字节流写入文件
f.write(response.content)
# 关闭文件
f.close()

 

 

案例2:

 

import requests
# 准备url
url = 'https://img-blog.csdnimg.cn/2020051614361339.jpg'
# 发送get请求
response = requests.get(url)
# 以二进制写入的方式打开图片文件
f = open('test.jpg', 'wb')
# 将文件流写入图片
f.write(response.content)
# 关闭文件
f.close()

 

 

 

 

转载自https://blog.csdn.net/suyongzhi1/article/details/117154748

 

posted @ 2021-06-01 14:09  2538  阅读(59)  评论(0编辑  收藏  举报