平时一步一步的操作也太麻烦了,直接上脚本就完事了。适用于gitee和github

#!/usr/bin/python
# -*- coding: utf-8 -*-
import time
import os
import sys
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common import alert
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support import wait
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.alert import Alert



def update():
####-----------------针对github和gitee----------------------------
os.system('d: && cd hexo && hexo clean && hexo g && hexo d') #文件夹路径,直接完成hexo clean; hexo g; hexo d的操作
####-----------------下面的主要是针对gitee自动化更新page,不用于github-------------------
# 模拟浏览器打开到gitee登录界面
driver = webdriver.Chrome()
# binary = FirefoxBinary('D:\Firefox\firefox.exe')
# driver = webdriver.Firefox(firefox_binary=binary)
driver.get('https://gitee.com/login')
# 将窗口最大化
# driver.maximize_window("chromedriver.exe")
time.sleep(2)

# 输入账号--通过html的id属性定位输入位置--改为你的账号
user_login = driver.find_element_by_id('user_login')
user_login.send_keys("your id")#填入你的账号
# 输入密码--通过html的id属性定位输入位置--改为你的密码
driver.find_element_by_id('user_password').send_keys("your password")#填入你的密码
# 点击登录按钮--通过xpath确定点击位置
driver.find_element_by_xpath(
'/html/body/div[2]/div[2]/div[1]/div/div[2]/div/form[1]/div[2]/div/div/div[4]/input').click()
time.sleep(2)

# 切换到gitee pages界面--改为you_gitee_id
driver.get('https://gitee.com/tordan/tordan/pages')
# 点击更新按钮--通过xpath确定点击位置
element = driver.find_element_by_xpath('//*[@id="pages-branch"]/div[7]')
ActionChains(driver).move_to_element(element).click().perform()
# 确认更新提示框--这个函数的作用是确认提示框
# Alert(driver).accept()
# dig_confirm = driver.switch_to.alert
# time.sleep(1)
# print(dig_confirm.text)
# dig_confirm.accept()
WebDriverWait(driver, 20, 0.5).until(EC.alert_is_present())
driver.switch_to.alert.text
driver.switch_to_alert().accept()


# 等待5秒更新
time.sleep(15)

# 这个print其实没事什么用,如果真的要测试脚本是否运行成功,可以用try来抛出异常
print("成功")

# 脚本运行成功,退出浏览器
driver.quit()

# 写上更新日志
# 我这里是写在D盘,可以改为自己喜欢的目录
fp = open("C://Users//13972//Desktop//log.txt", "a+")
now_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
fp.write('————————————————成功部署————————————————')
fp.write("部署时间:{0}\n".format(now_time))
fp.close()


def new():
print('输入文章名字')
a = sys.stdin.readline().strip('\n')
os.system('d: && cd hexo\source\_posts && hexo new %s && rd %s' % (a,a)) #博客文件夹路径
print('创建博客成功!!!')



def main():
print('请输入你的选择:')
print('1、创建博客')
print('2、更新博客')

input = sys.stdin.readline().strip('\n')
print("你的选择是:" + input)
if input == '1':
new()
elif input == '2':
update()


if __name__ == '__main__':
main()