本帖最后由 挑灯看花 于 2020-7-19 22:14 编辑
[Python] 纯文本查看 复制代码 class get_video_content(get_video_time,get_user_id):
def __init__(self,class_id,course_id):
self.course_id = course_id
self.class_id = class_id
get_user_id.__init__(self)
self.ts = get_timestamp()
self.url_get_video_content = "".format(course_id)
self.params_get_video_content = json.dumps({"class_id":class_id})
self.headers_get_video_content ={""
}
self.cookies = get_cookies()
self.video_list = []
self.parse_get_video_list()
self.video_list_queue = Queue()
for video_id in self.video_list:
# get_video_time.__init__(self,course_id,class_id,video_id,self.user_id)
self.video_list_queue.put(video_id)
self.list_thread = [] #进行多线程部分,其他不重要
for i in range(5):
t = threading.Thread(target = self.run_video_queue)
self.list_thread.append(t)
for t in self.list_thread:
t.setDaemon(True)
t.start()
self.video_list_queue.join()
def run_video_queue(self):
while True:
video_id = self.video_list_queue.get()
get_video_time.__init__(self,self.course_id,self.class_id,video_id,self.user_id)
self.video_list_queue.task_done()
def parse_get_video_list(self):
r = requests.post(self.url_get_video_content,headers = self.headers_get_video_content,cookies = self.cookies,data = self.params_get_video_content)
r = json.loads(r.content.decode())
for x in r["coursewareArray"]:
try:
video_id = x["children"]["items"]["item_id"]
video_complete = x["done"]
if not video_complete:
self.video_list.append(video_id)
except:
pass
代码写的比较烂 |