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

python使用requests库下载文件

watrt11个月前 (04-20)Python2680
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(...

python利用pyinstaller打包简明教程

python利用pyinstaller打包简明教程

在创建了独立应用(自包含该应用的依赖包)之后,还可以使用 PyInstaller 将 Python 程序生成可直接运行的程序,这个程序就可以被分发到对应的 Windows 或 Mac OS X 平台上运行。安装 PyInstallePython 默认并不包含 PyInstaller 模块,因此需要自行安装 PyInstaller 模块。安装 PyInstaller 模块与安装其他 Python 模块一样,使用 pip 命令安装即可。在命令行输入如下命令:pip install ...

发表评论

访客

看不清,换一张

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