Python下载工具—wget

转载自Python最强下载工具,比Requests强一百倍。

Python Wget是一个超好用文件下载库,可以用来方便的下载各类文件,帮我们省下很多时间。

安装:

pip install wget

1.下载文件:

import wgeturl = 'http://m801.music.126.net/20240530232316/79457cfe93200ea8af6a93b4c72f88d8/jdymusic/obj/wo3DlMOGwrbDjj7DisKw/26283602772/1a19/aba6/59e6/6f0737bf3343a393a1a8e532e428aaf6.flac'filename = wget.download(url)print(filename)

2.设置下载目录:

import wgeturl = 'https://example.com/file.txt'save_path = '/text/file.txt'wget.download(url, save_path)

3.设置自定义进度条

import wget  
def progress_bar(current, total, width=80):    progress = current / total    bar = '#' * int(progress * width)    percentage = round(progress * 100, 2)    print(f'[{bar:<{width}}] {percentage}%')url = 'http://m801.music.126.net/20240530232316/79457cfe93200ea8af6a93b4c72f88d8/jdymusic/obj/wo3DlMOGwrbDjj7DisKw/26283602772/1a19/aba6/59e6/6f0737bf3343a393a1a8e532e428aaf6.flac'save_path = '可惜没如果.mp3'  
wget.download(url, save_path, bar=progress_bar)

4.设置代理:

import wgeturl = 'https://example.com/file.txt'save_path = '/path/to/save/file.txt'proxy = 'http://proxy.example.com:8080'wget.download(url, save_path, proxy=proxy)


消息盒子

# 暂无消息 #

只显示最新10条未读和已读信息