[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)
效果
标签:title,python,self,selenium,element,click,phone,超星,find 来源: https://blog.csdn.net/General_zy/article/details/118031993