python+selenium 腳本實(shí)現(xiàn)每天自動(dòng)登記的思路詳解
最近受疫情影響,學(xué)校要求每天必須進(jìn)行健康登記,而我身處大山深處,身體健康,足不出戶,奈何總是容易忘記,遂決定手?jǐn)]一個(gè)自動(dòng)登記的小程序,僅供學(xué)習(xí)交流之用,話不多說(shuō),直接上代碼。
配置:Chrom python3.7 selenium庫(kù),webdriver等
基本思路,使用selenium模擬瀏覽器自動(dòng)登錄,需要解決驗(yàn)證碼的提取,嵌套表單的提取,彈窗處理,異常處理。
為了防止大家用此網(wǎng)站測(cè)試,搞垮服務(wù)器,關(guān)鍵網(wǎng)址我已隱藏。
import selenium.webdriver import time from bs4 import BeautifulSoup from selenium.webdriver.common.keys import Keys driver = selenium.webdriver.Chrome() url = '你的url' driver.get(url) source = driver.find_element_by_xpath('//p[@class="mb-md-5 mb-3 welcome-para"]/a') #source.get_attribute('href').click() ur2 = source.get_attribute('href') driver.get(ur2)#來(lái)到登錄界面 time.sleep(10) html = driver.page_source bs = BeautifulSoup(html,"html.parser") s = bs.findAll(name='div')[14].text[3:7] #獲得驗(yàn)證碼 time.sleep(5) #輸入用戶名,密碼,驗(yàn)證碼 driver.find_element_by_name("username").send_keys(你的賬號(hào)) driver.find_element_by_name("userpwd").send_keys(你的密碼) driver.find_element_by_name("code").send_keys(s) driver.find_element_by_name("login").click() time.sleep(5) #這里是解決頁(yè)面跳轉(zhuǎn)問(wèn)題,用了笨辦法 url3='你的url' driver.get(url3) time.sleep(5) driver.switch_to.frame('leftFrame') html = driver.page_source bs = BeautifulSoup(html,"html.parser") url4 = 'https://xsswzx.cdu.edu.cn:81/isp/com_user/' url5 = bs.findAll('a')[43].get('href') url6=url4+url5 driver.get(url6) time.sleep(5) driver.find_element_by_xpath('//input[@value="【一鍵登記:無(wú)變化】"]').click() dig_alert = driver.switch_to.alert dig_alert.accept() time.sleep(5) try: dig_alert = driver.switch_to.alert dig_alert.accept() except: pass time.sleep(10) try: driver.find_element_by_xpath('//input[@value="退出系統(tǒng)"]').click() except: driver.close() print("登記成功")
執(zhí)行此程序就可以實(shí)現(xiàn)登記了,但是并沒(méi)有實(shí)現(xiàn)每天自動(dòng)登記,下面我們結(jié)合Windows通過(guò)Anaconda定時(shí)調(diào)用python腳本,實(shí)現(xiàn)每天定時(shí)自動(dòng)登記。
首先編寫(xiě)一個(gè)bat腳本:
#此處為引用別人的內(nèi)容,參考鏈接:
https://zhuanlan.zhihu.com/p/50057040
配置好bat文件后
為了使電腦在關(guān)機(jī)的情況下也能自己開(kāi)機(jī)啟動(dòng)此程序(萬(wàn)一你睡過(guò)頭了呢,對(duì)吧),我們配置如下:
點(diǎn)擊確定,至此大功告成。
知識(shí)點(diǎn)補(bǔ)充:Python實(shí)現(xiàn)自動(dòng)填寫(xiě)網(wǎng)安早上登記信息
放在這里以后還可以參考!??!
from selenium import webdriver import time import schedule def auto_click(): var1 = 0 file = open('1.txt', 'r') list1 = [] for num in file: list1.append(num) list1 = list(map(int, list1)) while var1 < len(list1): driver = webdriver.Chrome() driver.maximize_window() driver.implicitly_wait(10) driver.get('http://acm.scu.edu.cn/student/weui/sars2.html?from=singlemessage') driver.find_element_by_xpath('//*[@id="number"]').send_keys(list1[var1]) driver.find_element_by_xpath('//*[@id="showTooltips"]').click() time.sleep(5) driver.quit() var1 += 1 schedule.every().day.at('16:19').do(auto_click) while True: schedule.run_pending() time.sleep(1)
到此這篇關(guān)于python+selenium 腳本實(shí)現(xiàn)每天自動(dòng)登記的思路詳解的文章就介紹到這了,更多相關(guān)python selenium 每天自動(dòng)登記內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- python selenium 執(zhí)行完畢關(guān)閉chromedriver進(jìn)程示例
- selenium+python實(shí)現(xiàn)自動(dòng)化登錄的方法
- Python + selenium自動(dòng)化環(huán)境搭建的完整步驟
- Python使用selenium實(shí)現(xiàn)網(wǎng)頁(yè)用戶名 密碼 驗(yàn)證碼自動(dòng)登錄功能
- selenium+python實(shí)現(xiàn)自動(dòng)登錄腳本
- 學(xué)習(xí)Python selenium自動(dòng)化網(wǎng)頁(yè)抓取器
- SpringBoot優(yōu)化啟動(dòng)速度的方法實(shí)現(xiàn)
相關(guān)文章
python使用py2neo創(chuàng)建neo4j的節(jié)點(diǎn)和關(guān)系
這篇文章主要介紹了python使用py2neo創(chuàng)建neo4j的節(jié)點(diǎn)和關(guān)系,第一步使用py2neo連接neo4j的方法然后根據(jù)dict創(chuàng)建Node,更多相關(guān)資料需要的朋友參考下面文章內(nèi)容2022-02-02Python3 Tkinkter + SQLite實(shí)現(xiàn)登錄和注冊(cè)界面
這篇文章主要為大家詳細(xì)介紹了Python3 Tkinkter + SQLite實(shí)現(xiàn)登錄和注冊(cè)界面,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-11-11python3實(shí)現(xiàn)基于用戶的協(xié)同過(guò)濾
這篇文章主要為大家詳細(xì)介紹了python3實(shí)現(xiàn)基于用戶的協(xié)同過(guò)濾,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05Python內(nèi)置函數(shù)locals和globals對(duì)比
這篇文章主要介紹了Python內(nèi)置函數(shù)locals和globals對(duì)比,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-04-04Python正則表達(dá)式實(shí)現(xiàn)截取成對(duì)括號(hào)的方法
這篇文章主要介紹了Python正則表達(dá)式實(shí)現(xiàn)截取成對(duì)括號(hào)的方法,涉及Python正則匹配相關(guān)操作技巧,需要的朋友可以參考下2017-01-01