[Python] 纯文本查看 复制代码 from selenium import webdriver
import pyautogui
import time
import re
#个人账号
username=pyautogui.prompt("请输入账号:")
#个人密码
passwd=pyautogui.prompt("请输入密码:")
login_url='https://www.nmgjxjy.com'
lesson_url='https://www.nmgjxjy.com/user/packets?flag=studying'
option = webdriver.ChromeOptions()
browser = webdriver.Chrome( chrome_options=option)
browser.maximize_window()
browser.get(login_url)
browser.implicitly_wait(10)
elem=browser.find_element_by_class_name("userNmae")
elem.send_keys(username)
time.sleep(1)
elem=browser.find_element_by_class_name("userPwd")
elem.send_keys(passwd)
time.sleep(1)
code_num=pyautogui.prompt("请输入验证码:")
elem=browser.find_element_by_class_name("userCode")
elem.send_keys(code_num)
elem=browser.find_element_by_xpath('/html/body/div[4]/div[1]/div[1]/div[1]/div/div[1]/form/div[5]/input')
elem.click()
time.sleep(3)
browser.find_element_by_xpath('/html/body/div[2]/div[1]/ul/li[2]/a/span').click()
time.sleep(3)
num=browser.find_elements_by_class_name("td_02")
print(len(num))
for i in range(0,len(num)):
lesson_xpath="/html/body/div[2]/div[3]/div[3]/div/div[2]/div/table/tbody/tr["+str(2+i)+"]/td[7]/a/img"
browser.find_element_by_xpath(lesson_xpath).click()
window = browser.window_handles
browser.switch_to_window(window[-1])
time.sleep(5)
next_num=re.findall("autoff",browser.page_source)
video_time=re.findall("\'0\'\,\'3\',\'(.*?)\'\,\'5",browser.page_source)
tr_id=re.findall('id="(autoff.*?)">',browser.page_source)
print(len(next_num))
print(video_time)
print(tr_id)
for g,m in zip(tr_id,video_time) :
xpath_code = '//*[@id="' + str(g) + '"]/td[4]/a/img'
watched_id = browser.find_element_by_xpath('//*[@id="' + str(g) + '"]/td[3]').text
print(watched_id) //增加一个判断、判断该视频是否已学习完
if watched_id == "否":
browser.find_element_by_xpath(xpath_code).click()
# 延迟100秒
lesson_timeout = int(str(m).split(".")[0]) * 60 + int(str(m).split(".")[1]) + 100
print(lesson_timeout)
time.sleep(lesson_timeout)
browser.back()
time.sleep(1)
browser.switch_to_alert().accept()
time.sleep(3)
browser.find_element_by_xpath('/html/body/div[2]/div[1]/ul/li[2]/a/span').click()
time.sleep(3) |