CNPM Binaries Mirror (npmmirror.com)
![](https://img.haomeiwen.com/i3968643/040c047b7351a4dd.png)
# project > CH7 > file_download2.py
import os
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from utils.get_file_path import get_download_path
path = get_download_path() + "/LATEST_RELEASE"
if os.path.exists(path):
print("文件存在")
os.remove(path)
print("文件已删除")
chromeOptions = webdriver.ChromeOptions()
prefs = {"download.default_directory": "{}".format(get_download_path())}
chromeOptions.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(chromeOptions)
driver.maximize_window()
driver.get("https://registry.npmmirror.com/binary.html?path=chromedriver/")
time.sleep(3)
driver.find_element(By.XPATH, '/html/body/table/tbody/tr[156]/td[2]/a').click()
time.sleep(3)
driver.close()
# project > utils > get_file_path.py
import os
def get_logo_path():
path = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))),"file","logo.bmp")
return path
# print(get_logo_path())
def get_download_path():
path = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))),"file")
return path
网友评论