python selenium 刷课_基于Python和selenium的内蒙古继续教育网---刷课
本帖最后由 lntuer 于 2019-9-16 18:14 編輯
目標網址:https://www.nmgjxjy.com/
解決問題:所選課程全部自動化
運行環境:Python3、selenium、chrome、pyautogui
聲明:僅限個人學習使用,嚴禁商業使用,否則后果自負(如有違規請版主刪除)
1.png (144.42 KB, 下載次數: 2)
2019-8-30 17:36 上傳
登陸網址
2.png (74.39 KB, 下載次數: 1)
2019-8-30 17:36 上傳
課程目錄
3.png (26.57 KB, 下載次數: 1)
2019-8-30 17:36 上傳
單個課程目錄
4.png (220.79 KB, 下載次數: 0)
2019-8-30 17:36 上傳
單個視頻
fromselenium importwebdriver
importpyautogui
importtime
importre
#個人賬號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))
fori inrange(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)
forg,m inzip(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) //增加一個判斷、判斷該視頻是否已學習完
ifwatched_id == "否":
browser.find_element_by_xpath(xpath_code).click()
# 延遲100秒lesson_timeout = int(str(m).split(".")[0]) * 60+ int(str(m).split(".")[1]) + 100print(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)
總結
以上是生活随笔為你收集整理的python selenium 刷课_基于Python和selenium的内蒙古继续教育网---刷课的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: uni-app url 传参有长度限制么
- 下一篇: Power BI 数据分析可视化软件入门