最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python?selenium模擬點(diǎn)擊問題解決方案

 更新時間:2022年05月10日 11:12:40   作者:魅Lemon  
這篇文章主要介紹了python?selenium模擬點(diǎn)擊問題,涉及到安裝谷歌瀏覽器和瀏覽器驅(qū)動的相關(guān)知識介紹,本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

1、安裝谷歌瀏覽器

#下載包
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
#安裝包,用deb方式安裝
sudo dpkg -i --force-depends google-chrome-stable_current_amd64.deb
#######################分割###############################
#若出現(xiàn)Packet xxx is not installed,代表依賴出現(xiàn)問題執(zhí)行以下命令
apt-get install -f
#重新執(zhí)行一遍
sudo dpkg -i --force-depends google-chrome-stable_current_amd64.deb
#######################分割##############################
#為了讓其能夠無界面運(yùn)行
sudo apt-get install xvfb

2、安裝瀏覽器驅(qū)動

#首先獲取chromedriver的最新版本信息
LATEST=$(wget -q -O - http://chromedriver.storage.googleapis.com/LATEST_RELEASE)
#下載  
wget http://chromedriver.storage.googleapis.com/$LATEST/chromedriver_linux64.zip  
#解壓
unzip chromedriver_linux64.zip  
#如果沒有安裝unzip就運(yùn)行 apt install unzip
#權(quán)限配置
chmod +x chromedriver  
#移動到bin目錄下
sudo mv chromedriver /usr/bin/

3、安裝selenium

#看自己系統(tǒng)是不是pip3,-i表示用什么源下載
pip3 install selenium -i https://pypi.tuna.tsinghua.edu.cn/simple

4、簡單測試

首先創(chuàng)建test.py文件,之后執(zhí)行python3 test.py,查看效果

#coding=utf-8
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_opt = Options()  # 創(chuàng)建參數(shù)設(shè)置對象.
chrome_opt.add_argument('--headless')  # 無界面化.
chrome_opt.add_argument('--disable-gpu')  # 配合上面的無界面化.
chrome_opt.add_argument('--window-size=1366,768')  # 設(shè)置窗口大小, 窗口大小會有影響.
chrome_opt.add_argument("--no-sandbox") #使用沙盒模式運(yùn)行
# 創(chuàng)建Chrome對象并傳入設(shè)置信息.
browser = webdriver.Chrome(chrome_options=chrome_opt)
url = "https://www.baidu.com/"
browser.get(url)
print(browser.page_source)
browser.quit()

5、打卡程序

這里我先用瀏覽器插件的Selenium先點(diǎn)擊好導(dǎo)出python文件進(jìn)行修改。程序需要創(chuàng)建data.csv文件,并在其中寫入賬號密碼

# Generated by Selenium IDE
import sys
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
# 讀取數(shù)據(jù)函數(shù)
userList = []
def readData():
  with open("data.csv","r") as f:
    for lines in f.readlines():
      data = lines.strip().split(",")
      userList.append(data)
# 全局函數(shù)
def printLog(info):
  print('{0}   {1}'.format(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())),info))
# 打卡類
class Test:
  # 初始化瀏覽器
  def __init__(self):
    # 添加 Chrome 相關(guān)配置
    options = webdriver.ChromeOptions()
    # 指定設(shè)備名稱即可
    options.add_experimental_option('mobileEmulation', {'deviceName': 'iPhone X'})
    options.add_argument('--no-sandbox')
    options.add_argument('--disable-dev-shm-usage')
    # options.add_argument('--headless')
    self.driver = webdriver.Chrome(chrome_options=options)  # => 打開瀏覽器時加入配置
    printLog("瀏覽器初始化完成")
  # 正式打卡
  def signIn(self,username,password):
    printLog("正在打開網(wǎng)頁")
    self.driver.get("http://stu.zstu.edu.cn/webroot/decision/url/mobile?origin=53fd9573-139e-4e3b-9357-4d791849ad58#/login")
    # 睡眠控制速度
    # 刷新頁面
    self.driver.refresh()
    time.sleep(3)
    self.driver.set_window_size(800, 824)
    self.driver.find_element(By.XPATH, "http://*[@id='app']/div/div[1]/div/div/div/div/div/div/div/div[2]/div[2]/div[1]/div/input").click()
    self.driver.find_element(By.XPATH, "http://*[@id='app']/div/div[1]/div/div/div/div/div/div/div/div[2]/div[2]/div[1]/div/input").send_keys(username)
    self.driver.find_element(By.XPATH, "http://input[@type=\'password\']").click()
    self.driver.find_element(By.XPATH, "http://input[@type=\'password\']").send_keys(password)
    time.sleep(3)
    self.driver.find_element(By.CSS_SELECTOR,".r-1loqt21:nth-child(4)").click()
    time.sleep(4)
    printLog("登錄成功")
    # 尋找打卡功能模塊
    self.driver.find_element(By.CSS_SELECTOR,".r-1loqt21:nth-child(2)").click()
    time.sleep(2)
    printLog("開始打卡")
    self.driver.find_element(By.CSS_SELECTOR, "#col_3_row_6 .css-901oao").click()
    time.sleep(1)
    self.driver.find_element(By.XPATH, "http://div[34]/div/div/div/div").click()
    time.sleep(1)
    self.driver.find_element(By.CSS_SELECTOR, "#col_4_row_6 > div").click()
    time.sleep(1)
    self.driver.find_element(By.XPATH, "http://div[2]/div/div[2]/div/div/div/div/div").click()
    time.sleep(1)
    self.driver.find_element(By.CSS_SELECTOR, "#col_5_row_6 > div").click()
    time.sleep(1)
    self.driver.find_element(By.XPATH, "http://div[2]/div/div[6]/div/div/div").click()
    time.sleep(1)
    self.driver.find_element(By.CSS_SELECTOR, "#col_3_row_7 .css-1cwyjr8").click()
    self.driver.find_element(By.CSS_SELECTOR, "#col_3_row_7 .css-1cwyjr8").send_keys("浙江理工大學(xué)")
    printLog("打卡進(jìn)行中")
    #選項(xiàng),不知道為什么css定位不能用
    self.driver.find_element(By.XPATH, "http://div[10]/div/div/div/div/div/div/div").click()
    self.driver.find_element(By.XPATH, "http://div[12]/div/div/div/div/div/div/div").click()
    self.driver.find_element(By.XPATH, "http://div[13]/div/div/div/div/div/div/div[2]").click()
    self.driver.find_element(By.XPATH, "http://div[17]/div/div/div/div/div/div/div").click()
    self.driver.find_element(By.XPATH, "http://div[18]/div/div/div/div/div/div/div").click()
    self.driver.find_element(By.XPATH, "http://div[19]/div/div/div/div/div[2]/div/div").click()
    self.driver.find_element(By.XPATH, "http://div[20]/div/div/div/div/div[2]/div/div").click()
    self.driver.find_element(By.XPATH, "http://div[21]/div/div/div/div/div[2]/div/div").click()
    self.driver.find_element(By.XPATH, "http://div[23]/div/div/div/div/div[2]/div/div").click()
    self.driver.find_element(By.XPATH, "http://div[25]/div/div/div/div/div/div/div").click()
    self.driver.find_element(By.XPATH, "http://div[26]/div/div/div/div/div[2]/div/div").click()
    self.driver.find_element(By.XPATH, "http://div[28]/div/div/div/div/div[2]/div/div").click()
    self.driver.find_element(By.XPATH, "http://div[30]/div/div/div/div/div[2]/div/div").click()
    time.sleep(1)
    #提交
    self.driver.find_element(By.CSS_SELECTOR, "#col_1_row_39").click()
    time.sleep(10)
    printLog("本次打卡成功")
  def quit(self):
    self.driver.quit()
    printLog("瀏覽器退出")
if __name__ == '__main__':
  test = Test()
  readData()
  for i in range(len(userList)):
    try:
      test.signIn(userList[i][0],userList[i][1])
    except:
      printLog("打卡成功或者系統(tǒng)bug,正在進(jìn)行下一個")
      continue
  test.quit()
  printLog("今日打卡任務(wù)完成")
  sys.exit()

6、linux設(shè)置定時任務(wù)

#上傳代碼后,設(shè)置定時
crontab -e 
#打開后添加以下記錄,代表每天3點(diǎn)執(zhí)行
0 3 * * * /usr/bin/python3 /home/shawn/ezl/sign.py > /home/shawn/ezl/elog.log 2>&1
#重啟
systemctl restart cron.service 

7、其他

上面部分為研究生打開,下面為本科生

# Generated by Selenium IDE
import sys
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
# 讀取數(shù)據(jù)函數(shù)
userList = []
def readData():
  with open("data.csv","r") as f:
    for lines in f.readlines():
      data = lines.strip().split(",")
      userList.append(data)
# 全局函數(shù)
def printLog(info):
  print('{0}   {1}'.format(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())),info))
# 打卡類
class Test:
  # 初始化瀏覽器
  def __init__(self):
    # 添加 Chrome 相關(guān)配置
    options = webdriver.ChromeOptions()
    # 指定設(shè)備名稱即可
    options.add_experimental_option('mobileEmulation', {'deviceName': 'iPhone X'})
    options.add_argument('--no-sandbox')
    options.add_argument('--disable-dev-shm-usage')
    options.add_argument('--headless')
    self.driver = webdriver.Chrome(chrome_options=options)  # => 打開瀏覽器時加入配置
    printLog("瀏覽器初始化完成")
  # 正式打卡
  def signIn(self,username,password):
    printLog("正在打開網(wǎng)頁")
    self.driver.get("http://stu.zstu.edu.cn/webroot/decision/url/mobile?origin=53fd9573-139e-4e3b-9357-4d791849ad58#/login")
    # 睡眠控制速度
    # 刷新頁面
    self.driver.refresh()
    time.sleep(3)
    self.driver.set_window_size(800, 824)
    self.driver.find_element(By.XPATH, "http://*[@id='app']/div/div[1]/div/div/div/div/div/div/div/div[2]/div[2]/div[1]/div/input").click()
    self.driver.find_element(By.XPATH, "http://*[@id='app']/div/div[1]/div/div/div/div/div/div/div/div[2]/div[2]/div[1]/div/input").send_keys(username)
    self.driver.find_element(By.XPATH, "http://input[@type=\'password\']").click()
    self.driver.find_element(By.XPATH, "http://input[@type=\'password\']").send_keys(password)
    time.sleep(3)
    self.driver.find_element(By.CSS_SELECTOR,".r-1loqt21:nth-child(4)").click()
    time.sleep(4)
    printLog("登錄成功")
    # 尋找打卡功能模塊
    # self.driver.find_element(By.CSS_SELECTOR,".r-1loqt21:nth-child(2)").click()
    self.driver.find_element(By.XPATH, "http://*[@id='app']/div/div[1]/div/div/div/div[1]/div/div/div/div/div/div[1]/div/div/div/div[2]/div/div/div[3]/div/div/div[5]/div/div/div[3]").click()
    time.sleep(5)
    printLog("開始打卡")
    # self.driver.find_element(By.CSS_SELECTOR, "#col_3_row_6 .css-901oao").click()
    self.driver.find_element(By.XPATH, "http://*[@id='col_1_row_11']/span").click()
    time.sleep(5)
    self.driver.find_element(By.XPATH, "http://div[2]/div/div/div/div/div/div/div/div/div/div/div").click()
    time.sleep(1)
    self.driver.find_element(By.XPATH, "http://div[34]/div/div/div/div").click()
    time.sleep(1)
    self.driver.find_element(By.XPATH, "http://div[2]/div/div/div/div/div/div/div/div/div/div[2]/div").click()
    time.sleep(1)
    self.driver.find_element(By.XPATH, "http://div[2]/div/div[2]/div/div/div/div/div/div").click()
    time.sleep(1)
    self.driver.find_element(By.XPATH, "http://div[3]/div").click()
    time.sleep(1)
    self.driver.find_element(By.XPATH, "http://div[6]/div/div/div/div").click()
    time.sleep(1)
    self.driver.find_element(By.XPATH, "http://input").click()
    time.sleep(1)
    self.driver.find_element(By.XPATH, "http://input").send_keys("浙江理工大學(xué)")
    time.sleep(1)
    printLog("打卡進(jìn)行中")
    #選項(xiàng),不知道為什么css定位不能用
    self.driver.find_element(By.XPATH, "http://div[11]/div/div/div/div/div/div/div").click()
    self.driver.find_element(By.XPATH, "http://div[13]/div/div/div/div/div/div/div").click()
    self.driver.find_element(By.XPATH, "http://div[14]/div/div/div/div/div/div/div").click()
    self.driver.find_element(By.XPATH, "http://div[18]/div/div/div/div/div/div/div[2]").click()
    self.driver.find_element(By.XPATH, "http://div[19]/div/div/div/div").click()
    self.driver.find_element(By.XPATH, "http://div[19]/div/div/div/div/div/div/div").click()
    self.driver.find_element(By.XPATH, "http://div[20]/div/div/div/div/div[2]/div/div").click()
    self.driver.find_element(By.XPATH, "http://div[21]/div/div/div/div/div[2]/div/div").click()
    self.driver.find_element(By.XPATH, "http://div[22]/div/div/div/div/div[2]/div/div").click()
    self.driver.find_element(By.XPATH, "http://div[24]/div/div/div/div/div[2]/div/div").click()
    self.driver.find_element(By.XPATH, "http://div[26]/div/div/div/div/div/div/div").click()
    self.driver.find_element(By.XPATH, "http://div[27]/div/div/div/div/div[2]/div/div").click()
    self.driver.find_element(By.XPATH, "http://div[29]/div/div/div/div/div[2]/div/div").click()
    self.driver.find_element(By.XPATH, "http://div[31]/div/div/div/div/div[2]/div/div").click()
    time.sleep(1)
    #提交
    self.driver.find_element(By.XPATH, "http://*[@id='col_0_row_40']/div/div/div/div").click()
    # self.driver.find_element(By.CSS_SELECTOR, "#col_0_row_40 .r-1loqt21 > .css-1dbjc4n").click()
    time.sleep(10)
    printLog("本次打卡成功")
  def quit(self):
    self.driver.quit()
    printLog("瀏覽器退出")
if __name__ == '__main__':
  test = Test()
  readData()
  for i in range(len(userList)):
    try:
      test.signIn(userList[i][0],userList[i][1])
    except:
      printLog("打卡成功或者系統(tǒng)bug,正在進(jìn)行下一個")
      continue
  test.quit()
  printLog("今日打卡任務(wù)完成")
  sys.exit()

=已經(jīng)失效,僅做參考=

到此這篇關(guān)于python selenium模擬點(diǎn)擊的文章就介紹到這了,更多相關(guān)python 模擬點(diǎn)擊內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Python學(xué)習(xí)筆記(一)(基礎(chǔ)入門之環(huán)境搭建)

    Python學(xué)習(xí)筆記(一)(基礎(chǔ)入門之環(huán)境搭建)

    本系列為Python學(xué)習(xí)相關(guān)筆記整理所得,IT人,多學(xué)無害,多多探索,激發(fā)學(xué)習(xí)興趣,開拓思維,不求高大上,只求懂點(diǎn)皮毛,作為知識儲備,不至于落后太遠(yuǎn)。本文主要介紹Python的相關(guān)背景,環(huán)境搭建。
    2014-06-06
  • python去除空格,tab制表符和\n換行符的小技巧分享

    python去除空格,tab制表符和\n換行符的小技巧分享

    這篇文章主要介紹了python去除空格,tab制表符和\n換行符的小技巧,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-01-01
  • 使用Python開發(fā)視頻格式轉(zhuǎn)換工具

    使用Python開發(fā)視頻格式轉(zhuǎn)換工具

    這篇文章主要介紹了如何使用Python開發(fā)一個帶圖形界面的視頻格式轉(zhuǎn)換工具,可以將WMV格式的視頻轉(zhuǎn)換為手機(jī)可以播放的MP4格式,需要的可以參考下
    2024-12-12
  • Python使用pandas和xlsxwriter讀寫xlsx文件的方法示例

    Python使用pandas和xlsxwriter讀寫xlsx文件的方法示例

    今天小編就為大家分享一篇關(guān)于Python使用pandas和xlsxwriter讀寫xlsx文件的方法示例,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2019-04-04
  • 解決同一目錄下python import報(bào)錯問題

    解決同一目錄下python import報(bào)錯問題

    這篇文章主要介紹了解決同一目錄下python import報(bào)錯問題,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-12-12
  • python編程線性回歸代碼示例

    python編程線性回歸代碼示例

    這篇文章主要介紹了python編程線性回歸代碼示例,具有一定借鑒價(jià)值,需要的朋友可以了解下。
    2017-12-12
  • Pytorch 高效使用GPU的操作

    Pytorch 高效使用GPU的操作

    這篇文章主要介紹了Pytorch 高效使用GPU的操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-06-06
  • 教你用Python尋找重復(fù)文件并刪除的腳本寫法

    教你用Python尋找重復(fù)文件并刪除的腳本寫法

    這篇文章主要介紹了如何用Python尋找重復(fù)文件并刪除,該腳本主要包括diskwalk,chechsum,find_dupes,delete模塊,其中diskwalk模塊是遍歷文件的,給定路徑,遍歷輸出該路徑下的所有文件,需要的朋友可以參考下
    2022-01-01
  • 六個實(shí)用Pandas數(shù)據(jù)處理代碼

    六個實(shí)用Pandas數(shù)據(jù)處理代碼

    這篇文章主要介紹了六個實(shí)用Pandas數(shù)據(jù)處理代碼,文章圍繞主題相相關(guān)內(nèi)容,具有一定的參考價(jià)價(jià)值,需要的小伙伴可以參考一下
    2022-05-05
  • jupyter notebook 實(shí)現(xiàn)matplotlib圖動態(tài)刷新

    jupyter notebook 實(shí)現(xiàn)matplotlib圖動態(tài)刷新

    這篇文章主要介紹了jupyter notebook 實(shí)現(xiàn)matplotlib圖動態(tài)刷新,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-04-04

最新評論

玉树县| 英吉沙县| 岳普湖县| 莒南县| 宿州市| 嘉义市| 玛曲县| 西充县| 广西| 石首市| 靖州| 剑阁县| 聂拉木县| 临洮县| 梁河县| 大足县| 甘泉县| 昭平县| 新龙县| 黄浦区| 黎平县| 辽宁省| 五峰| 井冈山市| 海安县| 德庆县| 青河县| 贵德县| 富锦市| 遂川县| 犍为县| 冕宁县| 饶阳县| 绍兴市| 津南区| 新乐市| 和林格尔县| 新田县| 合作市| 邹城市| 土默特右旗|