一、
先上網(wǎng)址

jkl.png
由于不需要驗(yàn)證碼,因此可以直接使用selenium實(shí)現(xiàn)簽到。
二、環(huán)境搭建
在阿里云ubuntu20.04服務(wù)器上無(wú)界面版的chrome瀏覽器存在驅(qū)動(dòng)問(wèn)題,因此改為Firefox。有關(guān)selenium的具體使用這里就不再贅述了。
1.安裝Firefox瀏覽器:
apt install firefox
安裝成功:

Firefox.png
2.安裝selenium
pip3 install selenium
3.下載驅(qū)動(dòng):geckodriver
解壓后上傳至服務(wù)器 /home/qiandao
4.移動(dòng)驅(qū)動(dòng)
mv geckodriver /usr/local/bin
5.測(cè)試一下
新建一個(gè)測(cè)試文件
vim firefoxtest.py
測(cè)試代碼
from selenium import webdriver
import time
url = 'https://www.baidu.com'
# 設(shè)置無(wú)界面模型
option = webdriver.FirefoxOptions()
option.add_argument('--headless')
driver = webdriver.Firefox(firefox_options=option, executable_path='/usr/local/bin/geckodriver')
driver.get(url)
print(driver.title)
運(yùn)行
python3 .\firefox.py
成功

ok.png
三、 簽到腳本
按F12打開(kāi)開(kāi)發(fā)者工具,選擇需要操作的元素,復(fù)制xpath路徑到代碼中

select.png
python代碼
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
import time
import logging
#打印一下日志
LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s"
logging.basicConfig(filename='qiandao.log', level=logging.INFO, format=LOG_FORMAT)
myusername = "1as5f@sdf.com"
mypassword = "124"
# 設(shè)置無(wú)界面模型
option = webdriver.FirefoxOptions()
option.add_argument('-headless') #無(wú)頭模式
option.set_preference('permissions.default.image',2) #不加載圖片
driver = webdriver.Firefox(firefox_options=option, executable_path='/usr/local/bin/geckodriver')
#模擬瀏覽器打開(kāi)網(wǎng)站
driver = webdriver.Firefox(firefox_options=option, executable_path='/usr/local/bin/geckodriver')
#模擬瀏覽器打開(kāi)網(wǎng)站
driver.get("https://jinkela.cyou/auth/login")
try:
#通過(guò)xpath路徑找到 用戶(hù)名、密碼 框,并輸入
driver.find_element(By.XPATH,"http://*[@id='email']").send_keys(myusername)
driver.find_element(By.XPATH,"http://*[@id='passwd']").send_keys(mypassword)
#模擬點(diǎn)擊登錄按鈕
driver.find_element(By.XPATH,"http://*[@id='login']").click()
time.sleep(7)
#模擬登陸后點(diǎn)擊簽到界面
#(我所模擬的頁(yè)面不需要這一步,因此不用加這一句)
#driver.find_element(By.XPATH,"/html/body/div[1]/div/form/div/div[5]/button").click()
#time.sleep(2)
#模擬點(diǎn)擊簽到按鈕
driver.find_element(By.XPATH,"http://*[@id='checkin']").click()
time.sleep(2)
driver.find_element(By.ID,"result_ok").click()
#print('當(dāng)前瀏覽地址為:.{0}'.format(driver.current_url))
logging.info("checkin success")
print("簽到成功")
except:
logging.error("checkin fault")
print("簽到失敗")
driver.quit() #退出驅(qū)動(dòng)
最后設(shè)置一下定時(shí)任務(wù),就可以每天自動(dòng)簽到了!
corntab -e進(jìn)入定時(shí)程序,
輸入0 7 * * * python3 /home/qiandao/firefoxqiandao.py,每天7點(diǎn)運(yùn)行
五、參考
服務(wù)器 配置ubuntu18.04 + selenium + firefox, 無(wú)界面讀取網(wǎng)頁(yè)_LG的博客-CSDN博客