from
selenium
import
webdriver
import
time
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(
120
)
wd.get(
"http://start.lgb360.com/video.html"
)
print
(
"正在自动登录!"
)
element
=
wd.find_element_by_xpath(
"/html/body/div/div[2]/div/div[1]/span[2]"
)
element.click()
element
=
wd.find_element_by_xpath(
"/html/body/div/div[2]/div/div[2]/ul[1]/li[4]/div/span"
)
element.click()
time.sleep(
1
)
element
=
wd.find_element_by_class_name(
"idCard"
)
element.send_keys(
'账号'
)
element
=
wd.find_element_by_class_name(
"password"
)
element.send_keys(
'密码'
)
element
=
wd.find_element_by_xpath(
"/html/body/div/div[2]/div/div[2]/ul[2]/li[4]/input"
)
element.click()
print
(
"请选择要学习的课程页面!"
)
time.sleep(
30
)
for
i
in
range
(
1
,
20
):
sj_xpath
=
"/html/body/div[1]/div[2]/div[1]/div[2]/div/div["
+
str
(i)
+
"]/div[1]/span"
sp_xpath
=
"/html/body/div[1]/div[2]/div[1]/div[2]/div/div["
+
str
(i)
+
"]/div[2]/ul/li[1]"
try
:
sjs
=
wd.find_elements_by_xpath(sj_xpath)
sp
=
wd.find_element_by_xpath(sp_xpath)
print
(
"即将播放:"
,sp.text)
sp.click()
for
sj
in
sjs:
try
:
n
=
re.findall(
"-?[0-9]\d*"
, sj.text)
print
(n)
m
=
int
(n[
2
])
*
60
+
int
(n[
3
])
print
(
"该视频秒数为:"
,m)
except
Exception as e:
pass
time.sleep(
int
(m))
time.sleep(
3
)
except
Exception as e:
pass