9***@qq.com
`--replace--` 自己改改 `青龙面板` 定时运行,数据很重要,还是要记得每个月登录一下
```
#!/usr/bin/env python
# coding: utf-8
# In[64]:
from selenium import webdriver
from selenium.webdriver import ChromeOptions
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
import base64, ddddocr, time
# In[65]:
# 打开浏览器,登录fine
option = ChromeOptions()
option.add_experimental_option('excludeSwitches', ['enable-automation'])
option.add_argument("--disable-blink-features=AutomationControlled")
# # local
chrome = webdriver.Chrome('--replace--', options=option)
chrome.execute_cdp_cmd(
"Page.addScriptToEvaluateOnNewDocument", {
"source":
"""
Object.defineProperty(navigator, 'webdriver', {
get: () => undefined
})
"""
})
# In[66]:
chrome.get('https://unicloud.dcloud.net.cn/login')
# In[67]:
uname = '--replace--'
pwd = '--replace--'
spaceId = '--replace--'
# In[68]:
def get_code():
code_base64 = WebDriverWait(chrome, 5).until(
EC.presence_of_element_located((
By.CSS_SELECTOR,
'div.container__login > div > form > div:nth-child(3) > div.login-captcha > img'
))).get_attribute('src')
authImg = open('./static/code.png', 'wb')
imgdata = base64.b64decode(code_base64.split(',')[-1])
authImg.write(imgdata)
authImg.close()
ocr = ddddocr.DdddOcr()
with open('./static/code.png', 'rb') as f:
img_bytes = f.read()
return ocr.classification(img_bytes)
# In[69]:
# 账号
WebDriverWait(chrome, 5).until(
EC.presence_of_element_located((
By.CSS_SELECTOR,
'div.container__login > div > form > div:nth-child(1) > div > input[type=text]'
))).send_keys(uname)
# 密码
WebDriverWait(chrome, 5).until(
EC.presence_of_element_located((
By.CSS_SELECTOR,
'div.container__login > div > form > div:nth-child(2) > div > input[type=password]'
))).send_keys(pwd)
# In[70]:
for i in range(10):
code = get_code()
# 验证码
WebDriverWait(chrome, 5).until(
EC.presence_of_element_located(
(By.CSS_SELECTOR,
'form > div:nth-child(3) > div.login-input > input[type=text]'
))).send_keys(code)
# 确定
WebDriverWait(chrome, 5).until(
EC.presence_of_element_located((
By.CSS_SELECTOR,
'div.container__login > div > form > div.login-btn > input[type=submit]'
))).click()
time.sleep(5)
if 'home' in chrome.current_url:
print('登录成功')
break
# In[71]:
ss = WebDriverWait(chrome, 5).until(
EC.presence_of_all_elements_located((
By.XPATH,
'//*[contains(@class,"el-table__body-wrapper")]/table/tbody/tr/td[2]/div/div/p'
)))
def findIndex(list, func):
for idx, i in enumerate(list):
if func(i):
return idx
else:
return -1
row_num = findIndex(ss, lambda x: x.text == spaceId)
# In[115]:
if row_num > -1:
css_node_find = f"#app > div > div > div > div > section > div > div.space-container > div > div.card-content > div.el-table.el-table--fit.el-table--striped.el-table--scrollable-x.el-table--enable-row-transition > div.el-table__fixed-right > div.el-table__fixed-body-wrapper > table > tbody > tr:nth-child({row_num+1}) > td.el-table_1_column_10.is-center > div > button.el-button.el-button--default.el-button--mini"
info_btn = WebDriverWait(chrome, 5).until(
EC.presence_of_element_located((By.CSS_SELECTOR, css_node_find)))
info_btn.click()
print(f'「{spaceId}」空间恢复活跃')
else:
print('空间未找到')
# %%
```
2022-06-01 16:06
151 个评论
该文章目前已经被锁定, 无法添加新评论
DCloud_云服务_moyang (作者)
l***@dingdinglv.com
xujingyuan
灳灳
贪恋他人娇妻
9***@qq.com
9***@qq.com
9***@qq.com
DCloud_云服务_moyang (作者)
eric_peng