from
selenium
import
webdriver
import
json
import
time
from
selenium.webdriver.common.action_chains
import
ActionChains
from
easygui
import
enterbox
import
re
chromedriver
=
'chromedriver.exe'
chome_options
=
webdriver.ChromeOptions()
wd
=
webdriver.Chrome(chromedriver, chrome_options
=
chome_options)
wd.delete_all_cookies()
wd.maximize_window()
wd.implicitly_wait(
60
)
wd.get(
"http://hrbj.21tb.com"
)
print
(
"访问页面成功!"
)
time.sleep(
15
)
element
=
wd.find_element_by_id(
"loginName"
)
element.send_keys(
"用户名"
)
element
=
wd.find_element_by_id(
"password"
)
element.send_keys(
"密码\n"
)
cookies
=
wd.get_cookies()
f1
=
open
(
'cookie.txt'
,
'w'
)
f1.write(json.dumps(cookies))
f1.close
f1
=
open
(
'cookie.txt'
)
cookie
=
f1.read()
cookie
=
json.loads(cookie)
for
c
in
cookie:
wd.add_cookie(c)
print
(
"登陆成功!"
)
time.sleep(
15
)
def
shuake(url):
wd.get(url)
print
(
"进入学习界面成功!"
)
time.sleep(
2
)
element
=
wd.find_element_by_tag_name(
"iframe"
)
play_url
=
element.get_attribute(
'src'
)
wd.get(play_url)
print
(
"进入实际播放页"
)
time.sleep(
5
)
elements
=
wd.find_elements_by_xpath(
'/html/body/div/div[2]/div[2]/div/ul[1]/div/li/span[2]'
)
play_times
=
[]
for
element
in
elements:
n
=
re.findall(
"-?[0-9]\d*"
,element.text)
m
=
int
(n[
0
])
*
60
+
int
(n[
1
])
play_times.append(m)
time.sleep(
3
)
element
=
wd.find_element_by_class_name(
"outter"
)
element.click()
print
(
"开始播放!"
)
for
play_time
in
play_times:
print
(
"本节课程播放用时需要"
, play_time,
"秒"
)
time.sleep(play_time)
time.sleep(
3
)
element
=
wd.find_element_by_class_name(
'next-button'
)
element.click()
print
(
"播放下一节成功!"
)
print
(
"播放本门课程结束!"
)
url
=
enterbox(msg
=
"请输入课程网址!"
)
shuake(url)