VSCODE配置 因为我并不准备把python作为我的主语言,所以我不准备用太大型的IDE,插件丰富的VSCODE对我来说就已经完全足够了。
首先,我们得先配置VSCODE的setting.json 由于我不想全局应用该项目的设置,所以我选择在根目录下创建 /.vscode/settings.json 单独应用于项目我的配置如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 { "python.defaultInterpreterPath" : "D:\\Program Files\\Python\\python.exe" , "python.autoComplete.extraPaths" : [ "D:/Program Files/Python/Lib/site-packages" , "D:/Program Files/Python/Scripts" ], "python.languageServer" : "Pylance" , "python.analysis.extraPaths" : [ "D:/Program Files/Python/Lib/site-packages" , "D:/Program Files/Python/Scripts" ], "terminal.integrated.defaultProfile.windows" : "GitBash" }
代码实现 至于 chromedriver 的下载 和模拟浏览器selenium则自行百度吧,我这里只贴具体代码了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 import timefrom selenium import webdriverfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.common.alert import Alertfrom selenium.webdriver.chrome.service import Servicefrom selenium.webdriver.support import expected_conditions as ECfrom selenium.webdriver.support.ui import WebDriverWait as Waitprint ("--------------开始运作---------------" )repo_user_name = "xxx" repo_name = "xxx" login_user = "xxx" login_pwd = "xxx" url = "https://gitee.com/" +repo_user_name+"/" +repo_name+"/pages" options = webdriver.ChromeOptions() options.add_argument("window-size=1920,1080" ) options.add_argument("start-maximized" ) options.add_argument("headless" ) options.add_experimental_option('excludeSwitches' , ['enable-logging' ]) driver = Service("D:/Download/chromedriver.exe" ) browser=webdriver.Chrome(service=driver,options=options) browser.get(url) Wait(browser, 10 ).until(EC.presence_of_element_located((By.CLASS_NAME, "item.gitee-nav-user .link" ))) login_btn = browser.find_elements(By.CLASS_NAME,"item.gitee-nav-user .link" ) login_btn[0 ].click() Wait(browser, 10 ).until(EC.presence_of_element_located((By.ID, "user_login" ))) Wait(browser, 10 ).until(EC.presence_of_element_located((By.ID, "user_password" ))) user_input = browser.find_element(By.ID,"user_login" ) pwd_input = browser.find_element(By.ID,"user_password" ) login_btn = browser.find_element(By.NAME,"commit" ) user_input.send_keys(login_user) pwd_input.send_keys(login_pwd) login_btn.click() Wait(browser, 10 ).until(EC.presence_of_element_located((By.CLASS_NAME, "button.orange.redeploy-button.ui.update_deploy" ))) print ("--------------登录完成---------------" )browser.find_element(By.XPATH,'//*[@id="pages-branch"]/div[6]' ).click() Alert(browser).accept() time.sleep(3 ) print ("--------------更新完成---------------" )browser.quit()
你也可以写进sh脚本里,实现一键部署hexo和gitee
1 2 3 4 5 hexo clean hexo g hexo d "/d/Program Files/Python/python.exe" "/d/Blog/hexo_buildGitee.py"