本帖最后由 lntuer 于 2020-3-21 22:54 编辑
一、学习网址
https://gbpx.gd.gov.cn/gdceportal/index.aspx
二、学习脚本
[Python] 纯文本查看 复制代码 from selenium import webdriver
import pyautogui
import time
#输入账号
username="****"
#输入密码
passwd="****"
login_url='https://gbpx.gd.gov.cn/gdceportal/index.aspx'
option = webdriver.ChromeOptions()
option.add_argument('--mute-audio')
browser = webdriver.Chrome(chrome_options=option)
browser.maximize_window()
browser.get(login_url)
browser.implicitly_wait(10)
elem=browser.find_element_by_xpath('//*[@id="pnlLogin"]/div[1]/div[2]')
elem.click()
time.sleep(1)
elem=browser.find_element_by_id("txtLoginName")
elem.clear()
elem.send_keys(username)
time.sleep(1)
elem=browser.find_element_by_id("txtPassword")
elem.clear()
elem.send_keys(passwd)
time.sleep(1)
code_num=pyautogui.prompt("请输入验证码:")
elem=browser.find_element_by_id("txtValid")
elem.clear()
elem.send_keys(code_num)
elem=browser.find_element_by_id('lnkbtnLogin')
elem.click()
time.sleep(3)
elem=browser.find_element_by_id('ctl00_CPHMain_btnStudy')
elem.click()
time.sleep(3)
browser.switch_to_frame('ifrContent')
time.sleep(1)
js_001='return document.getElementsByClassName("courseware-list-reed").length;'
video_unstudy_num=browser.execute_script(js_001)
time.sleep(3)
print("该目录下还有{}个视频未学习……".format(video_unstudy_num))
for i in range(0,int(video_unstudy_num)):
js_006='document.getElementsByClassName("courseware-list-reed")[{}].click()'.format(i)
unstudy_lession_urls=browser.execute_script(js_006)
time.sleep(3)
小白需要安装好Python和selenium的环境,大神请直接忽略本代码
2020.3.21更新
解决填表内容改了,需要手机验证才可以登录
|