iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >Python如何实现智慧校园一键评教
  • 184
分享到

Python如何实现智慧校园一键评教

2023-06-15 07:06:44 184人浏览 安东尼

Python 官方文档:入门教程 => 点击学习

摘要

小编给大家分享一下python如何实现智慧校园一键评教,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!一、安装selenium库问题1:什么是selenium模块?基于浏览器自动化的一个模块。 问题2:seleni

小编给大家分享一下python如何实现智慧校园一键评教,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

一、安装selenium

问题1:什么是selenium模块?

 问题2:selenium模块有什么作用呢?

  • 便捷地获取网站中动态加载的数据

  • 便捷地实现模拟登录

问题3:环境安装

pip install selenium

二、下载一个浏览器的驱动程序(谷歌浏览器)

1.下载路径

Http://chromedriver.storage.Googleapis.com/index.html

2.驱动程序和浏览器的映射关系(谷歌浏览器)

方法1:[不推荐]

在浏览器地址栏输入:chrome://version/

Python如何实现智慧校园一键评教

  • 复制版本号,只取前三节

示例:版本号为90.0.4430.212,只需复制90.0.4430

  • 将复制的数字加到https://chromedriver.storage.googleapis.com/LATEST_RELEASE_后面

示例:https://chromedriver.storage.googleapis.com/LATEST_RELEASE_90.0.4430

博主尝试了没有成功

Python如何实现智慧校园一键评教

方法2:[推荐]

安装WEBdriver-manager

pip install webdriver-manager

运行如下代码

import timefrom selenium import webdriverfrom webdriver_manager.chrome import ChromeDriverManager# from webdriver_manager.microsoft import EdgeChromiumDriverManageroptions = 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()

很简单,省很多事

三、智慧校园评教实现

1.新建python文件导入相关包

from selenium import webdriverimport timefrom lxml import etree

2. 使用selenium打开登录页面

# 实例化一个浏览器对象bro = webdriver.Chrome(executable_path='./chromedriver')# 驱动程序所在路径# 让浏览器发起一个指定url对应请求bro.get('http://sso.cqcet.edu.cn/login')

Python如何实现智慧校园一键评教

3.录入用户名密码,点击登录按钮实现登录

# 标签定位username_input = bro.find_element_by_id('username')passWord_input = bro.find_element_by_id('password')# 标签交互username_input.send_keys('**********')# 智慧校园账号password_input.send_keys('**********')# 智慧校园密码# 点击登入按钮btn = bro.find_element_by_class_name('logon-btn')btn.click()time.sleep(2)# 停顿2s

Python如何实现智慧校园一键评教

4.进入教学评价系统

# 点击学评教管理bro.get('http://ossc.cqcet.edu.cn/xg/teaching/student/index/teach')bro.find_element_by_class_name('nav-label').click()time.sleep(2)# 点击学生评教bro.get('http://ossc.cqcet.edu.cn/xg/teaching/student/xskb')# page_source获取浏览器当前页面的页面源码数据page_text = bro.page_source

Python如何实现智慧校园一键评教

5.实现评教操作

# 解析onclick里面的内容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如何实现智慧校园一键评教

6.完成效果图

Python如何实现智慧校园一键评教

四、附录

以下为实现谷歌无头浏览器和反检测代码,供参考

from selenium import webdriverfrom time import sleep#实现无可视化界面from selenium.webdriver.chrome.options import Options#实现规避检测from selenium.webdriver import ChromeOptions#实现无可视化界面的操作chrome_options = Options()chrome_options.add_argument('--headless')chrome_options.add_argument('--disable-gpu')#实现规避检测option = ChromeOptions()option.add_experimental_option('excludeSwitches', ['enable-automation'])#如何实现让selenium规避被检测到的风险bro = webdriver.Chrome(executable_path='./chromedriver',chrome_options=chrome_options,options=option)#无可视化界面(无头浏览器) phantomjsbro.get('https://www.baidu.com')print(bro.page_source)sleep(2)bro.quit()

看完了这篇文章,相信你对“Python如何实现智慧校园一键评教”有了一定的了解,如果想了解更多相关知识,欢迎关注编程网Python频道,感谢各位的阅读!

--结束END--

本文标题: Python如何实现智慧校园一键评教

本文链接: https://www.lsjlt.com/news/278419.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作