溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Python如何實現(xiàn)智慧校園一鍵評教

發(fā)布時間:2021-05-28 10:24:11 來源:億速云 閱讀:324 作者:小新 欄目:開發(fā)技術(shù)

小編給大家分享一下Python如何實現(xiàn)智慧校園一鍵評教,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!

一、安裝selenium庫

問題1:什么是selenium模塊?

  • 基于瀏覽器自動化的一個模塊。

 問題2:selenium模塊有什么作用呢?

  • 便捷地獲取網(wǎng)站中動態(tài)加載的數(shù)據(jù)

  • 便捷地實現(xiàn)模擬登錄

問題3:環(huán)境安裝

pip install selenium

二、下載一個瀏覽器的驅(qū)動程序(谷歌瀏覽器)

1.下載路徑

http://chromedriver.storage.googleapis.com/index.html

2.驅(qū)動程序和瀏覽器的映射關(guān)系(谷歌瀏覽器)

方法1:[不推薦]

在瀏覽器地址欄輸入:chrome://version/

Python如何實現(xiàn)智慧校園一鍵評教

  • 復(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

博主嘗試了沒有成功

Python如何實現(xiàn)智慧校園一鍵評教

方法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()

很簡單,省很多事

三、智慧校園評教實現(xiàn)

1.新建python文件導(dǎo)入相關(guān)包

from selenium import webdriver
import time
from lxml import etree

2. 使用selenium打開登錄頁面

# 實例化一個瀏覽器對象
bro = webdriver.Chrome(executable_path='./chromedriver')# 驅(qū)動程序所在路徑
# 讓瀏覽器發(fā)起一個指定url對應(yīng)請求
bro.get('http://sso.cqcet.edu.cn/login')

Python如何實現(xiàn)智慧校園一鍵評教

3.錄入用戶名密碼,點(diǎn)擊登錄按鈕實現(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

Python如何實現(xiàn)智慧校園一鍵評教

4.進(jìn)入教學(xué)評價系統(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

Python如何實現(xiàn)智慧校園一鍵評教

5.實現(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()

Python如何實現(xiàn)智慧校園一鍵評教

6.完成效果圖

Python如何實現(xiàn)智慧校園一鍵評教

四、附錄

以下為實現(xiàn)谷歌無頭瀏覽器和反檢測代碼,供參考

from selenium import webdriver
from time import sleep
#實現(xiàn)無可視化界面
from selenium.webdriver.chrome.options import Options
#實現(xiàn)規(guī)避檢測
from selenium.webdriver import ChromeOptions

#實現(xiàn)無可視化界面的操作
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')

#實現(xiàn)規(guī)避檢測
option = ChromeOptions()
option.add_experimental_option('excludeSwitches', ['enable-automation'])

#如何實現(xiàn)讓selenium規(guī)避被檢測到的風(fēng)險
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()

看完了這篇文章,相信你對“Python如何實現(xiàn)智慧校園一鍵評教”有了一定的了解,如果想了解更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI