Python趣味爬蟲之用Python實(shí)現(xiàn)智慧校園一鍵評教
一、安裝selenium庫
問題1:什么是selenium模塊?
- 基于瀏覽器自動化的一個模塊。
問題2:selenium模塊有什么作用呢?
- 便捷地獲取網(wǎng)站中動態(tài)加載的數(shù)據(jù)
- 便捷地實(shí)現(xiàn)模擬登錄
問題3:環(huán)境安裝
pip install selenium
二、下載一個瀏覽器的驅(qū)動程序(谷歌瀏覽器)
1.下載路徑
http://chromedriver.storage.googleapis.com/index.html
2.驅(qū)動程序和瀏覽器的映射關(guān)系(谷歌瀏覽器)
方法1:[不推薦]
在瀏覽器地址欄輸入:chrome://version/
- 復(fù)制版本號,只取前三節(jié)
示例:版本號為90.0.4430.212
,只需復(fù)制90.0.4430
- 將復(fù)制的數(shù)字加到
https://chromedriver.storage.googleapis.com/LATEST_RELEASE_
后面
示例:https://chromedriver.storage.googleapis.com/LATEST_RELEASE_90.0.4430
博主嘗試了沒有成功
方法2:[推薦]
安裝webdriver-manager
庫
pip install webdriver-manager
運(yùn)行如下代碼
import time from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager # from webdriver_manager.microsoft import EdgeChromiumDriverManager options = webdriver.ChromeOptions() options.add_argument('--ignore-certificate-errors') driver = webdriver.Chrome(ChromeDriverManager().install(),chrome_options=options) # driver = webdriver.Edge(EdgeChromiumDriverManager().install()) driver.get('https://www.baidu.com/s?wd=123') driver.close()
很簡單,省很多事
三、智慧校園評教實(shí)現(xiàn)
1.新建python文件導(dǎo)入相關(guān)包
from selenium import webdriver import time from lxml import etree
2. 使用selenium打開登錄頁面
# 實(shí)例化一個瀏覽器對象 bro = webdriver.Chrome(executable_path='./chromedriver')# 驅(qū)動程序所在路徑 # 讓瀏覽器發(fā)起一個指定url對應(yīng)請求 bro.get('http://sso.cqcet.edu.cn/login')
3.錄入用戶名密碼,點(diǎn)擊登錄按鈕實(shí)現(xiàn)登錄
# 標(biāo)簽定位 username_input = bro.find_element_by_id('username') password_input = bro.find_element_by_id('password') # 標(biāo)簽交互 username_input.send_keys('**********')# 智慧校園賬號 password_input.send_keys('**********')# 智慧校園密碼 # 點(diǎn)擊登入按鈕 btn = bro.find_element_by_class_name('logon-btn') btn.click() time.sleep(2)# 停頓2s
4.進(jìn)入教學(xué)評價(jià)系統(tǒng)
# 點(diǎn)擊學(xué)評教管理 bro.get('http://ossc.cqcet.edu.cn/xg/teaching/student/index/teach') bro.find_element_by_class_name('nav-label').click() time.sleep(2) # 點(diǎn)擊學(xué)生評教 bro.get('http://ossc.cqcet.edu.cn/xg/teaching/student/xskb') # page_source獲取瀏覽器當(dāng)前頁面的頁面源碼數(shù)據(jù) page_text = bro.page_source
5.實(shí)現(xiàn)評教操作
# 解析onclick里面的內(nèi)容 tree = etree.HTML(page_text) onclick_list = tree.xpath('//*[@id="bootstrap-table"]/tbody//a/@onclick') print(onclick_list) for onclick in onclick_list: if onclick[0:15] != "checkEvaluation": bro.execute_script(onclick) time.sleep(1) bro.find_element_by_class_name('layui-layer-btn0').click() time.sleep(1) time.sleep(5) bro.quit()
6.完成效果圖
四、附錄
以下為實(shí)現(xiàn)谷歌無頭瀏覽器和反檢測代碼,供參考
from selenium import webdriver from time import sleep #實(shí)現(xiàn)無可視化界面 from selenium.webdriver.chrome.options import Options #實(shí)現(xiàn)規(guī)避檢測 from selenium.webdriver import ChromeOptions #實(shí)現(xiàn)無可視化界面的操作 chrome_options = Options() chrome_options.add_argument('--headless') chrome_options.add_argument('--disable-gpu') #實(shí)現(xiàn)規(guī)避檢測 option = ChromeOptions() option.add_experimental_option('excludeSwitches', ['enable-automation']) #如何實(shí)現(xiàn)讓selenium規(guī)避被檢測到的風(fēng)險(xiǎn) bro = webdriver.Chrome(executable_path='./chromedriver',chrome_options=chrome_options,options=option) #無可視化界面(無頭瀏覽器) phantomJs bro.get('https://www.baidu.com') print(bro.page_source) sleep(2) bro.quit()
到此這篇關(guān)于Python趣味挑戰(zhàn)之用Python實(shí)現(xiàn)智慧校園一鍵評教的文章就介紹到這了,更多相關(guān)Python智慧校園一鍵評教內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- 快速一鍵生成Python爬蟲請求頭
- 使用Python制作一個數(shù)據(jù)預(yù)處理小工具(多種操作一鍵完成)
- 如何打包Python Web項(xiàng)目實(shí)現(xiàn)免安裝一鍵啟動的方法
- 利用Python代碼實(shí)現(xiàn)一鍵摳背景功能
- Ubuntu18.04 一鍵升級Python所有第三方包 及安裝python包的方法
- Python一鍵安裝全部依賴包的方法
- Python一鍵查找iOS項(xiàng)目中未使用的圖片、音頻、視頻資源
- Python 一鍵獲取百度網(wǎng)盤提取碼的方法
- Python 一鍵制作微信好友圖片墻的方法
- Python字典循環(huán)添加一鍵多值的用法實(shí)例
相關(guān)文章
Pandas之StyleFrame如何設(shè)置表格樣式
這篇文章主要介紹了Pandas之StyleFrame如何設(shè)置表格樣式,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-07-07用Python實(shí)現(xiàn)服務(wù)器中只重載被修改的進(jìn)程的方法
這篇文章主要介紹了用Python實(shí)現(xiàn)服務(wù)器中只重載被修改的進(jìn)程的方法,包括用watchdog來檢測文件的變化等,實(shí)現(xiàn)起來充分體現(xiàn)了Python作為動態(tài)語言的靈活性,強(qiáng)烈推薦!需要的朋友可以參考下2015-04-04Python實(shí)現(xiàn)CART決策樹算法及詳細(xì)注釋
CART算法是一種樹構(gòu)建算法,既可以用于分類任務(wù),又可以用于回歸,本文僅討論基本的CART分類決策樹構(gòu)建,不討論回歸樹和剪枝等問題,感興趣的朋友跟隨小編一起看看吧2021-10-10Python判斷一個文件夾內(nèi)哪些文件是圖片的實(shí)例
今天小編就為大家分享一篇Python判斷一個文件夾內(nèi)哪些文件是圖片的實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-12-12Python實(shí)現(xiàn)識別手寫數(shù)字 Python圖片讀入與處理
這篇文章主要為大家詳細(xì)介紹了Python實(shí)現(xiàn)識別手寫數(shù)字,Python圖片的讀入與處理,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-01-01Python實(shí)現(xiàn)將HTML轉(zhuǎn)換成doc格式文件的方法示例
這篇文章主要介紹了Python實(shí)現(xiàn)將HTML轉(zhuǎn)換成doc格式文件的方法,涉及Python htmlparser及docx模塊的相關(guān)使用技巧,需要的朋友可以參考下2017-11-11Tornado服務(wù)器中綁定域名、虛擬主機(jī)的方法
這篇文章主要介紹了Tornado服務(wù)器中綁定域名、虛擬主機(jī)的方法,本人查看了Tornado才得的方法,特此分享,需要的朋友可以參考下2014-08-08