[python自动化]selenium实现超星某某通自动评论
2021/6/18 20:27:26
本文主要是介绍[python自动化]selenium实现超星某某通自动评论,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
目录
- 思路
- 代码封装
- 效果
思路
- 使用selenium提供的函数实现标签的定位与页面的切换。
- 编写js代码找上者无法定位的标签(jQuery简单应用)
- selenium执行js代码
代码封装
from selenium import webdriver from time import sleep class AutoComment: js = "let submitEle=$('.qdBtn');" \ "submitEle.click();" def __init__(self, phone, password): self.phone = phone self.password = password def start(self, path, name): """ 开始评论 :param name: 课程名 :param path: 本地Edge浏览器驱动的路径 :return: """ b = webdriver.Edge(path) b.get('https://passport2.chaoxing.com/login?fid=&newversion=true&refer=http%3A%2F%2Fi.chaoxing.com') b.maximize_window() b.find_element_by_id('phone').send_keys(self.phone) b.find_element_by_id('pwd').send_keys(self.password) b.find_element_by_id('loginBtn').click() sleep(2) b.switch_to.frame('frame_content') b.find_element_by_link_text(name).click() windows = b.window_handles b.switch_to.window(windows[-1]) b.find_element_by_link_text('讨论').click() for i in range(50): title = b.find_element_by_id('c_title') title.click() title.send_keys(i) b.execute_script(self.js) b.switch_to.alert.accept() sleep(2)
效果
这篇关于[python自动化]selenium实现超星某某通自动评论的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python