Gitee pages自动部署

admin 2022年4月10日00:23:53评论50 views字数 1535阅读5分7秒阅读模式

一、前期准备

1.1 安装环境

1、安装python3 2、打开命令行安装selenium

1
pip install selenium

二、python代码

2.1 源码

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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import time
from selenium import webdriver
from selenium.webdriver.common.alert import Alert

# 模拟浏览器打开到gitee登录界面
driver = webdriver.Chrome()
driver.get('https://gitee.com/login')
# 将窗口最大化
driver.maximize_window()
time.sleep(2)

# 输入账号--通过html的id属性定位输入位置--改为你的账号
user_login = driver.find_element_by_id('user_login')
user_login.send_keys("此处改为你的账号")
# 输入密码--通过html的id属性定位输入位置--改为你的密码
driver.find_element_by_id('user_password').send_keys("此处改为你的密码")
# 点击登录按钮--通过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/此处改为you_gitee_id/此处改为you_gitee_id/pages')
# 点击更新按钮--通过xpath确定点击位置
driver.find_element_by_xpath('/html/body/div[3]/div[2]/div/div[2]/div[1]/form/div[7]').click()
# 确认更新提示框--这个函数的作用是确认提示框
Alert(driver).accept()

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

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

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

# 写上更新日志
# 我这里是写在D盘,可以改为自己喜欢的目录
fp = open("D:\log.txt", "a+")
now_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
fp.write("auto update time:{0}\n".format(now_time))
fp.close()

2.2 注意事项

  • xpath可以通过在chrom的网页里面按F12来查看

  • 演示过程

    )image-20210820212050702

  • 需要将chromeDrive可执行驱动丢到你python根目录(跟python.exe放在一起)

下载地址

1
http://chromedriver.storage.googleapis.com/index.html

FROM:gylq.gitee Author:孤桜懶契

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年4月10日00:23:53
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Gitee pages自动部署http://cn-sec.com/archives/729900.html

发表评论

匿名网友 填写信息