开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
forked from Benjamin/Python
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (2)
master
develop
master
分支 (2)
master
develop
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (2)
master
develop
Python
/
catchPageApp.py
Python
/
catchPageApp.py
catchPageApp.py 25.26 KB
一键复制 编辑 原始数据 按行查看 历史
Benjamin 提交于 2020年06月22日 10:36 +08:00 . 'autoCheckLogin'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author:Benjamin
import tkinter as tk # 使用Tkinter前需要先导入
from tkinter import *
from tkinter.ttk import *
import tkinter.messagebox
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import datetime
import asyncio
import threading
from threading import Thread
from threading import Timer
import os
class PFDataHelper:
@staticmethod
def DateFormat():
return '%Y-%m-%d'
class PFPageCatcher:
'Perfect爬虫类'
def __init__(self, userName, pwd):
self._userName = userName
self._pwd = pwd
def login(self):
#https需要
# profile=webdriver.FirefoxProfile()
# profile.accept_untrusted_certs=True
# profile=webdriver.ChromeProfile()#报错
# self.driver = webdriver.Firefox(firefox_profile=profile)
self.driver = webdriver.Chrome()
driver=self.driver
driver.set_page_load_timeout(5000)
#尝试登陆:https://www.cnblogs.com/andy9468/p/10901608.html
loginUrl="https://zxy9.zhixueyun.com/oauth/#login/cmVzcG9uc2VfdHlwZT10b2tlbiZjbGllbnRfaWQ9OTk5JnJlZGlyZWN0X3VyaT1odHRwcyUzQSUyRiUyRnBlcmZlY3QuemhpeHVleXVuLmNvbSZzdGF0ZT0lMkZob21lJmxhbmc9Y24mY2FuY2VsUmVtZW1iZXJTdGF0ZT0w"
#loginUrl="http://192.168.0.26:28102/User/Login?ReturnUrl=%2f"
driver.get(loginUrl)
print('打开了页面')
time.sleep(5) #driver.get之后要等待页面加载完(有的情况下get会自动等待加载完)--benjamin
# # 点击账号和密码登录
#input_username = driver.find_element_by_xpath("//input[@name='userid']")
# input_password = driver.find_element_by_xpath("//input[@name='password']")
# input_box0 = driver.find_element_by_xpath("//input[@class='btn']")
input_username = driver.find_element_by_xpath("//input[@name='username']")
input_password = driver.find_element_by_xpath("//input[@name='pword']")
input_box0 = driver.find_element_by_xpath("//button[@class='btn-login']")
input_username.send_keys(u"1712002")
input_password.send_keys(u"123456a")
# # input_username.value="aaa"
input_box0.click()
print('点击了登陆按钮')
time.sleep(8)#10)
def getHtml(self):
# return self.driver.page_source.get_text()
return self.driver.page_source
def getPage(self,url):
self.driver.get(url)
time.sleep(5)
return self.driver.page_source
# def getLesson(self):
# driver=self.driver
# # videoListUrl="https://perfect.zhixueyun.com/#/study/subject/detail/a4068ba4-891e-4b04-8aca-c1365bd68fb2"
# # #videoListUrl="https://perfect.zhixueyun.com/api/v1/course-study/subject/chapter-progress?courseId=a4068ba4-891e-4b04-8aca-c1365bd68fb2&_=1590047045850"
# # driver.get(videoListUrl)
# time.sleep(10)
# #return driver.page_source
# soup = BeautifulSoup(driver.page_source, 'lxml')
# print(driver.page_source)
# #div=soup.find('div',attrs={'class':'name-des'})
# #print(div.get_text())
# # result=[]
# # #return soup.body.select('div[class=item] div[data-resource-id]')
# # print(soup.body)
# # # for img_tag in soup.body.select('div[class=item][data-resource-id]'):
# # # for img_tag in soup.body.select('div[class=item] div[data-resource-id]'):
# # for img_tag in soup.body.select('div[class=name-des]'):
# # print(img_tag.text)
# # result+=[img_tag.text]
# # return result
# # print(img_tag.attrs['href'])
class PfCatcherForm:
def __init__(self):
#默认参数
# defaultLessonUrl="https://perfect.zhixueyun.com/#/study/subject/detail/8247851a-a8a1-446a-988d-51697e32114b"
defaultLessonUrl="https://perfect.zhixueyun.com/#/study/course/index"
defaultUserName="1712002"
# defaultUserName=""
# 第1步,实例化object,建立窗口window
window = tk.Tk()
# 第2步,给窗口的可视化起名字
window.title("自动学习程序")
# 第3步,设定窗口的大小(长 * 宽)
window.geometry('750x720') # 这里的乘是小x
# 第4步,在图形界面上设定标签
l = tk.Label(window, text='你好!本 python 程序由 Benjamin 开发', bg='green', font=('Arial', 12), width=30, height=2)
# 说明: bg为背景,font为字体,width为长,height为高,这里的长和高是字符的长和高,比如height=2,就是标签有2个字符这么高
# 第5步,放置标签
l.pack() # Label内容content区域放置位置,自动调节尺寸
# 放置lable的方法有:1)l.pack(); 2)l.place();
userNameLabel = tk.Label(window, text='用户名:', bg='green', font=('Arial', 12), width=30, height=1)
userNameLabel.pack()
#userNameLabel.grid(row=0, column=0, padx=10, pady=10, ipadx=10, ipady=10)
self.userNameInputStr =StringVar(value=defaultUserName)
userNameInput = tk.Entry(window, textvariable=self.userNameInputStr,show=None, font=('Arial', 14))
userNameInput.pack()
userPwdLabel = tk.Label(window, text='密码:', bg='green', font=('Arial', 12), width=30, height=1)
userPwdLabel.pack()
self.userPwdInputStr =StringVar(value="123456a")
userPwdInput = tk.Entry(window, textvariable=self.userPwdInputStr,show=None, font=('Arial', 14))
userPwdInput.pack()
lessonUrlLabel = tk.Label(window, text='课程地址:', bg='green', font=('Arial', 12), width=30, height=1)
lessonUrlLabel.pack()
self.lessonUrlInputStr =StringVar(value=defaultLessonUrl)
lessonUrlInput = tk.Entry(window, textvariable=self.lessonUrlInputStr,show=None, font=('Arial', 14))
lessonUrlInput.pack()
self.pageInput= tk.Text(window,height = 5)
self.lessonInput= tk.Text(window,height = 5)
self.lessonListInput= tk.Text(window,height = 5)
processLabel = tk.Label(window, text='进度:', bg='green', font=('Arial', 12), width=30, height=1)
processLabel.pack()
self.processInputStr =StringVar(value="0/0")
processInput = tk.Entry(window, textvariable=self.processInputStr,show=None, font=('Arial', 14),state='readonly')
processInput.pack()
learnedTimeLabel = tk.Label(window, text='已学习:', bg='green', font=('Arial', 12), width=30, height=1)
learnedTimeLabel.pack()
self.learnedTimeInputStr =StringVar(value="")
learnedTimeInput = tk.Entry(window, textvariable=self.learnedTimeInputStr,show=None, font=('Arial', 14),state='readonly')
learnedTimeInput.pack()
self.startAfterLoginInt = tk.IntVar()
self.startAfterLoginInt.set(1)
startAfterLoginInput = tk.Checkbutton(window,text = "登陆后自动开始",variable = self.startAfterLoginInt,onvalue = 1,offvalue = 0)
startAfterLoginInput.pack()
self.autoPunchLoginInt = tk.IntVar(value=1)
autoPunchLoginInput = tk.Checkbutton(window,text = "自动打卡",variable = self.autoPunchLoginInt,onvalue = 1,offvalue = 0)
autoPunchLoginInput.pack()
self.autoShutdownInt = tk.IntVar()
autoShutdownInput = tk.Checkbutton(window,text = "完成时关机",variable = self.autoShutdownInt,onvalue = 1,offvalue = 0)
autoShutdownInput.pack()
self.loginInput=tk.Button(window, text='登陆', bg='green', font=('Arial', 14), command=self.asyncLogin )
self.loginInput.pack()
# self.playCurPageInput=tk.Button(window, text='播放当前列表页', bg='green', font=('Arial', 14), command=self.asyncPlayCurPage )
# self.playCurPageInput.pack()
self.pageInput.pack()
self.lessonInput.pack()
self.lessonListInput.pack()
self.isLogin=0
self.pfCatcher=None
self.lastPushTime='' #上次打卡时间
# 第6步,主窗口循环显示
# self.root=window
# self.root.protocol("WM_DELETE_WINDOW", self.on_closing)
window.mainloop()
# 注意,loop因为是循环的意思,window.mainloop就会让window不断的刷新,如果没有mainloop,就是一个静态的window,传入进去的值就不会有循环,mainloop就相当于一个很大的while循环,有个while,每点击一次就会更新一次,所以我们必须要有循环
# 所有的窗口文件都必须有类似的mainloop函数,mainloop是窗口文件的关键的关键。
# def on_closing(self):
# # self.new_loop.close()
# # self.t.destroy()
# self.t.cancel()
# self.root.destroy()
# asyncio
def asyncLogin(self):
#return await _thread.start_new_thread( self.doCalculate, ("Thread-1", 2, ) )#报错:RuntimeWarning: Enable tracemalloc to get the object allocation traceback
# _thread.start_new_thread( self.doCalculate, () )
self.t = Thread(target=self.login,args=()) #通过当前线程开启新的线程去启动事件循环
self.t.start()
# def asyncPlayCurPage(self):
# #return await _thread.start_new_thread( self.doCalculate, ("Thread-1", 2, ) )#报错:RuntimeWarning: Enable tracemalloc to get the object allocation traceback
# # _thread.start_new_thread( self.doCalculate, () )
# self.t = Thread(target=self.playCurPage,args=()) #通过当前线程开启新的线程去启动事件循环
# self.t.start()
# def test(self):
# loop = asyncio.new_event_loop()
# loop.run_until_complete(self.login())
# loop.close()
def doPlayCurPage(self):
# #判断是哪一种课程页,类型参考E:\web\html_all\study\自动在线学习程序_readme.txt
# if self.lessonUrlInputStr.get().find('perfect.zhixueyun.com/#/study/subject/detail')>-1:
# self.lessonUrlType=1 #https://perfect.zhixueyun.com/#/study/subject/detail/8247851a-a8a1-446a-988d-51697e32114b
# else:
# self.lessonUrlType=2 #https://perfect.zhixueyun.com/#/study/course/index
# self.curLessonPage=1 #这种类型是分页的
lessonPage=self.pfCatcher.getHtml()
soup = BeautifulSoup(lessonPage, 'lxml')
self.lessons=[]
if self.lessonUrlType==1:
items = soup.select('.name-des')
for item in items:
li=item.parent.parent
title=item.get('title')
btn=li.select('i.iconfont div')[0].get_text()
attachmentId=li.get('data-resource-id')
print(title )#attrs字典取属性
print(btn )#attrs字典取属性
self.lessons+=[{'title':title,'btn': btn,'attachmentId':attachmentId}]
else:
items = soup.select('li.list-item')
for item in items:
urlItem=item.select('.content-bottom a')[0]
title=urlItem.get_text()
url=urlItem.get('href')
btnItem=item.select('.content .img .study-status')
if len(btnItem)>0:
btn=btnItem[0].get_text()
else:
btn=''
if btn=="已完成":
btn="重新学习"
self.lessons+=[{'title':title,'btn':btn,'url':url}]
# items = soup.select('li.list-item .content-bottom a')
# for item in items:
# title=item.get_text()
# url=item.get('href')
# self.lessons+=[{'title':title,'url':url}]
self.lessonListInput.insert(1.0,self.lessons)
self.lessonCnt=len(self.lessons)
self.playLesson(self.pfCatcher)
# def goToNextPage(self):
# soup=BeautifulSoup(self.pfCatcher.getHtml(), 'lxml')
# idx=int(soup.select('.pagination .active')[0].get_text()) #这种类型是分页的
# nextIdx=idx+1
# nextBtn=soup.select('.pagination .item[data-page="{0}"]'.format(nextIdx))
# if len(nextBtn)>0:
# tmpstr="//div[@class='pagination']/div[@data-page='{0}']".format(nextIdx)
# self.pfCatcher.driver.find_element_by_xpath(tmpstr).click()
# time.sleep(2)
# return 1
# else:
# return 0
def goToPage(self):
# self.pfCatcher.getPage(self.lessonUrlInputStr.get())
# while self.goToNextPage()==1:
# nextBtn=BeautifulSoup(self.pfCatcher.getHtml(), 'lxml').select('.pagination .item[data-page="{0}"]'.format(self.curLessonPage))
nextBtn=BeautifulSoup(self.pfCatcher.getPage(self.lessonUrlInputStr.get()), 'lxml').select('.pagination .item[data-page="{0}"]'.format(self.curLessonPage))#如果上一次也是在列表页,即url没变化的话,找第5页就已经找不到了
if len(nextBtn)>0:
return 1 #5页之前都是可以直接一次切换
#有时页面超时打不开,页面都是空的--benjamin20200603
while len(BeautifulSoup(self.pfCatcher.getHtml(), 'lxml').select('.pagination .active'))<1:
return -1
# self.pfCatcher.getPage(self.lessonUrlInputStr.get())
#8页之后要一次一次切换
curP=int(BeautifulSoup(self.pfCatcher.getHtml(), 'lxml').select('.pagination .active')[0].get_text())+1
while curP<=self.curLessonPage:
nextBtn=BeautifulSoup(self.pfCatcher.getHtml(), 'lxml').select('.pagination .item[data-page="{0}"]'.format(curP))
if len(nextBtn)>0:
tmpstr="//div[@class='pagination']/div[@data-page='{0}']".format(curP)
self.pfCatcher.driver.find_element_by_xpath(tmpstr).click()
# nextBtn0 = self.pfCatcher.driver.find_element_by_xpath(tmpstr)
# time.sleep(1)#这里不延迟好像会有问题,因为find_element_by_xpath调用后页面会刷新一下的
# nextBtn0.click()
time.sleep(2)
else:
return 0
curP+=1
return 1
# if curP>=self.curLessonPage:
# return 1
# return 0
def playCurPage(self):
self.startTime=datetime.datetime.now()
# self.lessonUrlInputStr.set(self.pfCatcher.driver.current_url)
#判断是哪一种课程页,类型参考E:\web\html_all\study\自动在线学习程序_readme.txt
if self.lessonUrlInputStr.get().find('perfect.zhixueyun.com/#/study/subject/detail')>-1:
self.lessonUrlType=1 #https://perfect.zhixueyun.com/#/study/subject/detail/8247851a-a8a1-446a-988d-51697e32114b
else:
self.lessonUrlType=2 #https://perfect.zhixueyun.com/#/study/course/index
self.curLessonPage=int(BeautifulSoup(self.pfCatcher.getHtml(), 'lxml').select('.pagination .active')[0].get_text()) #这种类型是分页的
# lessonPage=self.pfCatcher.getHtml()
# soup = BeautifulSoup(lessonPage, 'lxml')
# self.lessons=[]
# if self.lessonUrlType==1:
# items = soup.select('.name-des')
# for item in items:
# li=item.parent.parent
# title=item.get('title')
# btn=li.select('i.iconfont div')[0].get_text()
# attachmentId=li.get('data-resource-id')
# print(title )#attrs字典取属性
# print(btn )#attrs字典取属性
# self.lessons+=[{'title':title,'btn': btn,'attachmentId':attachmentId}]
# else:
# items = soup.select('li.list-item')
# for item in items:
# urlItem=item.select('.content-bottom a')[0]
# title=urlItem.get_text()
# url=urlItem.get('href')
# btnItem=item.select('.content .img .study-status')
# if len(btnItem)>0:
# btn=btnItem[0].get_text()
# else:
# btn=''
# if btn=="已完成":
# btn="重新学习"
# self.lessons+=[{'title':title,'btn':btn,'url':url}]
# # items = soup.select('li.list-item .content-bottom a')
# # for item in items:
# # title=item.get_text()
# # url=item.get('href')
# # self.lessons+=[{'title':title,'url':url}]
# self.lessonListInput.insert(1.0,self.lessons)
# self.lessonCnt=len(self.lessons)
if self.lessonUrlType==1:
self.doPlayCurPage()
else:#找下一页
hasPage=1
while hasPage==1:
self.doPlayCurPage()
self.curLessonPage+=1
hasPage=self.goToPage()
while hasPage==-1:#网络错误重试
hasPage=self.goToPage()
# nextBtn=BeautifulSoup(self.pfCatcher.getPage(self.lessonUrlInputStr.get()), 'lxml').select('.pagination .item[data-page="{0}"]'.format(self.curLessonPage))
# if len(nextBtn)>0:
# tmpstr="//div[@class='pagination']/div[@data-page='{0}']".format(self.curLessonPage)
# nextBtn0 = self.pfCatcher.driver.find_element_by_xpath(tmpstr)
# time.sleep(5)#这里不延迟好像会有问题,因为find_element_by_xpath调用后页面会刷新一下的
# nextBtn0.click()
# time.sleep(5)
# else:
# hasPage=0
self.processInputStr.set("已完成")
self.loginInput.config(state='normal',text='重新学习')
# self.playCurPageInput.config(state="normal")
if self.autoShutdownInt.get()==1:
os.system('shutdown -s -f -t 59') #取消关机命令 shutdown /a
def playCurLesson(self,pfCatcher):
# learnedTime=datetime.datetime.now()-self.startTime
lesson=self.lessons[self.curIdx]
# self.learnedTimeInputStr.set('{0}分'.format(round(learnedTime.seconds/60,2)))
if self.lessonUrlType==1:
self.processInputStr.set('{0}/{1}'.format(self.curIdx,self.lessonCnt))
pfCatcher.getPage("https://perfect.zhixueyun.com/#/study/course/detail/10&{0}/6/1".format(lesson['attachmentId']))
else:
self.processInputStr.set('{0}/{1} 第{2}页'.format(self.curIdx,self.lessonCnt,self.curLessonPage))
# pfCatcher.getPage("https://perfect.zhixueyun.com/{0}".format(lesson['url']))
pfCatcher.getPage("https://perfect.zhixueyun.com/{0}/6/1".format(lesson['url']))#后面没有6/1时不能播放,试试加上(似乎有了6/1就能自动播放)--benjamin20200528
# def playLesson(self,pfCatcher):
# self.curIdx=0
# cnt=len(self.lessons)
# self.startTime=datetime.datetime.now()
# self.playCurLesson(pfCatcher)
# self.t = Timer(1,self.playCurLesson,args=()) #通过当前线程开启新的线程去启动事件循环
# self.t.start()
# def playLesson(self,pfCatcher):
# self.curIdx=0
# cnt=len(self.lessons)
# self.startTime=datetime.datetime.now()
# for lesson in self.lessons:
# learnedTime=datetime.datetime.now()-self.startTime
# self.processInputStr.set('{0}/{1}'.format(self.curIdx,cnt))
# # learnedTimeInputStr.set('{0}时{1}分{2}秒'.format(learnedTime.hours,learnedTime.minutes,learnedTime.seconds))
# self.learnedTimeInputStr.set('{0}分'.format(learnedTime.seconds/60))
# if lesson['btn']!='重新学习':
# pfCatcher.getPage("https://perfect.zhixueyun.com/#/study/course/detail/10&{0}/6/1".format(lesson['attachmentId']))
# time.sleep(900)#1)#(900)
# self.curIdx+=1
# self.processInputStr.set("已完成")
# self.loginInput.config(state='normal',text='重新学习')
# if self.autoShutdownInt.get()==1:
# os.system('shutdown -s -f -t 59')
# def scriptClick(self,ele,idx):
# self.pfCatcher.driver.execute_script("arguments[0].click();".format(str(idx)), ele)
def clickExceptOther(self,netErrorEle):
# netErrorEle=self.pfCatcher.driver.find_element_by_xpath("//div[@class='vjs-netslow']//div[@class='slow-img']")
self.pfCatcher.driver.execute_script("arguments[0].click();", netErrorEle)
def pushIn(self):#打卡
nowtime=datetime.datetime.now().strftime(PFDataHelper.DateFormat())
if self.autoPunchLoginInt.get()==1 and self.lastPushTime!=nowtime:
self.pfCatcher.getPage('https://perfect.zhixueyun.com/#/ask/index')
# self.pfCatcher.driver.find_element_by_xpath("//div[@class='publish-btn']").click()
#上句报错is not clickable at point (862, 18). Other element would receive the click: <div
#id="D66message-id" class="menu-item">...</div>
self.clickExceptOther(self.pfCatcher.driver.find_element_by_xpath("//div[@class='publish-btn']"))
self.lastPushTime=nowtime
time.sleep(2)
self.pfCatcher.driver.find_element_by_xpath("//div[@class='form relative pulish-content-page']//input[@name='title']").send_keys(u"打卡")
# self.pfCatcher.driver.find_element_by_xpath("//div[@class='tag-btn radius ' and text()='打卡']").click()
time.sleep(1)
self.pfCatcher.driver.find_element_by_xpath("//div[@class='dialog-footer']//div[@class='btn' and text()='发布']").click()
time.sleep(3)
self.pfCatcher.driver.refresh()
time.sleep(2)
#打卡之后弹窗不能关闭,要刷新
def playLesson(self,pfCatcher):
self.pushIn()
self.curIdx=0
cnt=len(self.lessons)
while self.curIdx<cnt:
lesson=self.lessons[self.curIdx]
if ('btn' not in lesson) or lesson['btn']!='重新学习':
self.playCurLesson(pfCatcher)
time.sleep(10)#(900)
finishCnt=0
while finishCnt==0:
learnedTime=datetime.datetime.now()-self.startTime
self.learnedTimeInputStr.set('{0}分'.format(round(learnedTime.seconds/60,2)))
soup=BeautifulSoup(pfCatcher.getHtml(), 'lxml')
finishDom=soup.find('div', text="您已完成该课程的学习")
if finishDom is not None:
finishCnt=1
continue
netErrorDom=soup.find('div', text="网络不稳定,请刷新重试")
if netErrorDom is not None:
#self.pfCatcher.driver.refresh()
try:
netErrorEle=self.pfCatcher.driver.find_element_by_xpath("//div[@class='vjs-netslow']//div[@class='slow-img']")
self.pfCatcher.driver.execute_script("arguments[0].click();", netErrorEle)
except BaseException as e:
print(e)
# netErrorEle.click()
# webdriver.ActionChains(self.pfCatcher.driver).move_to_element(netErrorEle ).click(netErrorEle ).perform()
time.sleep(2)
continue
goawayDom=soup.find('p', text="亲爱的学员,目前学习正在计时中,请不要走开哦!")
if goawayDom is not None:
try:
self.pfCatcher.driver.find_element_by_xpath("//div[@class='alert-wrapper']//div[@class='btn-ok btn']").click()
except BaseException as e:
print(e)
time.sleep(2)
continue
openOtherDom=soup.find('div', text="您已打开新的课程详情页,点击按钮,可继续学习。")
if openOtherDom is not None:
try:
self.pfCatcher.driver.find_element_by_xpath("//div[@class='study-errors-page']//div[@class='btn']").click()
except BaseException as e:
print(e)
time.sleep(2)
continue
replayDom=soup.find('button',attrs={'class': 'videojs-referse-btn'})#重新播放按钮
if replayDom is not None and 'vjs-hidden' not in replayDom.get('class'):
finishCnt=1
# self.pfCatcher.driver.find_element_by_xpath("//div[@class='videojs-referse-btn']").click()
# time.sleep(2)
continue
videoDom=soup.find('video',attrs={'class': 'vjs-tech'}) #如果没有找到这个元素,认为页面加载失败(()可能是网络原因)
if videoDom is None:
if self.isLoginTimeout()==1:
self.pfCatcher.login()
self.playCurLesson(pfCatcher)
continue
else:
self.pfCatcher.driver.refresh()
time.sleep(5)
continue
time.sleep(20)
self.curIdx+=1
def isLoginTimeout(self):#是否登陆失效
soup=BeautifulSoup(self.pfCatcher.getHtml(), 'lxml')
loginBtnDom=soup.find('button',attrs={'class': 'btn-login'})#重新播放按钮
if loginBtnDom is not None:
return 1
else:
return 0
# def checkLogin(self):#如果登陆失效的话重新登陆
# soup=BeautifulSoup(self.pfCatcher.getHtml(), 'lxml')
# loginBtnDom=soup.find('button',attrs={'class': 'btn-login'})#重新播放按钮
# if loginBtnDom is not None:
# self.pfCatcher.login()
# return 1
# return 0
def login(self):
if tk.messagebox.askokcancel(title='Hi', message=self.userNameInputStr.get()):
self.loginInput.config(state="disabled")
# self.playCurPageInput.config(state="disabled")
if self.isLogin==1:#如果是已登陆的状态,就播放当前打开的页面,而不是lessonUrlInputStr
self.lessonUrlInputStr.set(self.pfCatcher.driver.current_url)
self.playCurPage()
else :
self.pfCatcher=PFPageCatcher(self.userNameInputStr.get(),self.userPwdInputStr.get())
self.pfCatcher.login()
self.isLogin=1
# if self.autoPunchLoginInt.get()==1:
# self.pfCatcher.getPage('https://perfect.zhixueyun.com/#/ask/index')
# self.pfCatcher.driver.find_element_by_xpath("//div[@class='publish-btn']").click()
# time.sleep(2)
# self.pfCatcher.driver.find_element_by_xpath("//div[@class='form relative pulish-content-page']//input[@name='title']").send_keys(u"打卡")
# # self.pfCatcher.driver.find_element_by_xpath("//div[@class='tag-btn radius ' and text()='打卡']").click()
# time.sleep(1)
# self.pfCatcher.driver.find_element_by_xpath("//div[@class='dialog-footer']//div[@class='btn' and text()='发布']").click()
# time.sleep(3)
# self.pfCatcher.driver.refresh()
# time.sleep(2)
# #打卡之后弹窗不能关闭,要刷新
html=self.pfCatcher.getHtml()
lessonPage=self.pfCatcher.getPage(self.lessonUrlInputStr.get())
self.pageInput.insert(1.0,html)
self.lessonInput.insert(1.0,lessonPage)
if self.startAfterLoginInt.get()==1:
self.playCurPage()
else:
self.loginInput.config(state='normal',text='开始学习')
if __name__=='__main__':
form=PfCatcherForm()
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

Python projects.something like web crawler
暂无标签
MulanPSL-1.0
使用 MulanPSL-1.0 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/aihacker_045/Python.git
git@gitee.com:aihacker_045/Python.git
aihacker_045
Python
Python
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /