编程学习网 > 编程语言 > Python > Python最强下载工具,比Requests强一百倍!
2024
05-31

Python最强下载工具,比Requests强一百倍!


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


安装:
pip install wget

1.下载文件:

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


2.设置下载目录:

import wget
url = '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 wget
url = '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)

以上就是Python最强下载工具,比Requests强一百倍!的详细内容,想要了解更多Python教程欢迎持续关注编程学习网。

扫码二维码 获取免费视频学习资料

Python编程学习

查 看2022高级编程视频教程免费获取