参考:
方法一:wget
import wget, os# 设置下载路径os.chdir(r"D:/tmp")url="https://files.cnblogs.com/files/alex-bn-lee/ESRI_01.zip"# 获取下载文件名称filename = wget.detect_filename(url)# 文件下载wget.download(url)
方法二:urllib.request(python 3.x 与 2.x 有区别)
import urllib.requesturl = 'https://files.cnblogs.com/files/alex-bn-lee/ESRI_01.zip' # 需要自定义文件名称urllib.request.urlretrieve(url, "demo.zip")
方法三:通过打开浏览器自动下载,需要控制键盘和鼠标
import pynput, webbrowser, timefrom pynput.mouse import Buttonfrom pynput.keyboard import Keymouse = pynput.mouse.Controller()keyboard = pynput.keyboard.Controller()url = 'https://files.cnblogs.com/files/alex-bn-lee/ESRI_01.zip' # 打开网页webbrowser.open(url)# 反应时间time.sleep(2)keyboard.press(Key.enter)keyboard.release(Key.enter)time.sleep(1)mouse.click(Button.left)# 通过 Ctrl+w 快捷键删除当前页面with keyboard.pressed(Key.ctrl): keyboard.press('w') keyboard.release('w')