【331】python 下载文件:wget / urllib
方法一: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.request url = 'https://files.cnblogs.com/files/alex-bn-lee/ESRI_01.zip' # 需要自定义文件名称 urllib.request.urlretrieve(url, "demo.zip")
方法三:通过打开浏览器自动下载,需要控制键盘和鼠标
import pynput, webbrowser, time from pynput.mouse import Button from pynput.keyboard import Key mouse = 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')
posted on 2018-07-09 16:54 McDelfino 阅读(3179) 评论(0) 编辑 收藏 举报