当前位置:首页 > 技术 > Python > 正文内容

python使用requests库下载文件

watrt1年前 (2023-04-20)Python4020
import os
import requests


def downfile(url):
	try:
		url=url.split("@")[0].split("?")[0]
		urlfile=url.split("/")[-1]
		print(urlfile)
	except Exception as e:
		print("地址不正确")
	data= requests.get(url);
	if(data.status_code==200):
		with open(urlfile,"wb") as f:
			f.write(data.content)
	else:
		print("404错误")
if __name__ == '__main__':
	downfile("http://xb6.cn/tools/espy_cn/espy_CN.rar")
	pass


分享给朋友:

相关文章

esp32外部中断学习笔记

esp32外部中断学习笔记

思路:我使用的esp32开发板为简易的开发板,因为板上没有用户自己定义的键盘所以在使用中想要输入或者控制无法完成。研究发现在开发板上有的下载按钮是不是可以在进入系统后复用为一个按键呢。实现:参考官方的例程对代码如下首先宏定义参数:#define KYE_0   0    //GPIO0检测 #define KEYS_SET   (1ULL<<0) &nb...

python编写的简单http请求和应答

python编写的简单http请求和应答

响应(服务端)import machine import socket pins = [machine.Pin(i, machine.Pin.IN) for i in (0, 2, 4, 5, 12, 13, 14, 15)] adc = machine.ADC(0) html = &quo...

micropython中使用rtc设置时间

micropython中使用rtc设置时间

micropython中使用rtc设置时间from machine import RTC rtc = RTC() rtc.datetime((2017, 8, 23, 1, 12, 48, 0, 0)) # set a specific date and time print(rtc.datetime(...

micropython 使用oled显示前面设置的时间。

micropython 使用oled显示前面设置的时间。

from machine import I2C, Pin import ssd1306,time    #这里引用的是官方的ssd1306库。可以在github上下载下来放入库中。 i2c = I2C(-1, Pin(14), Pin(2)) display = ssd1306.SSD1306_I2C(128, 64, i...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。