资源简介
导出pdf:由于图片含有防爬密钥,转成PDF阅读体验更佳
解析TS文件,压制成mp4:遍历文章id,获取m3u8地址,解析每个ts的key解密,按顺序排列,压制成mp4文件(如果有ffmpeg压制方案可以追加,ffmpeg可以指定视频为h264编码格式,可用于OSS存储web端播放).目前是本地写了批量转码脚本;

代码片段和文件信息
# coding=utf-8
import threading
import queue
import requests
import json
import time
import pdfkit
import ahttp
import os
from upload import Upload_oss
import asyncio
import oss2
import re
class LaGou_article():
def __init__(self courseId):
self.url = ‘https://gate.lagou.com/v1/neirong/kaiwu/getCourseLessons?courseId=‘+courseId
self.headers = {
‘User-Agent‘: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML like Gecko) Chrome/77.0.3865.90 Safari/537.36‘
‘Cookie‘: ‘登录拉勾视频网站,截取请求头里的cookie,去掉第一个参数‘
‘Referer‘: ‘https://kaiwu.lagou.com/course/courseInfo.htm?courseId=‘+courseId
‘Origin‘: ‘https://kaiwu.lagou.com‘
‘Sec-fetch-dest‘: ‘empty‘
‘Sec-fetch-mode‘: ‘cors‘
‘Sec-fetch-site‘: ‘same-site‘
‘x-l-req-header‘: ‘{deviceType:1}‘}
# 发现课程文章html的请求url前面都是一样的最后的id不同而已
self.textUrl = ‘https://gate.lagou.com/v1/neirong/kaiwu/getCourseLessonDetail?lessonId=‘
self.queue = queue.Queue() # 初始化一个队列
self.error_queue = queue.Queue()
self.courseId = courseId
def replace_all_blank(self value):
“““
去除value中的所有非字母内容,包括标点符号、空格、换行、下划线等
:param value: 需要处理的内容
:return: 返回处理后的内容
“““
# \W 表示匹配非数字字母下划线
result = re.sub(‘\W+‘ ‘‘ value).replace(“_“ ‘‘)
return result
def parse_one(self):
“““
:return:获取文章html的url
“““
content = requests.get(url=self.url headers=self.headers).text
code_cont = json.loads(content)
message_list = code_cont[‘content‘][‘courseSectionList‘]
# print(message_list)
for message in message_list:
for i in message[‘courseLessons‘]:
real_url = self.textUrl+str(i[‘id‘])
self.queue.put(real_url) # 文章的请求url
return self.queue
def courseInfo(self):
“““
:return:获取文章的详细内容
“““
content = requests.get(url=self.url headers=self.headers).text
info = json.loads(content)
return info[‘content‘]
def get_html(self real_url):
“““
:return:返回一个Str 类型的html
“““
html = requests.get(url=real_url timeout=10
headers=self.headers).text
dit_message = json.loads(html)
str_html = str(dit_message[‘content‘][‘textContent‘])
article_name = dit_message[‘content‘][‘theme‘]
self.htmltopdf(str_html article_name)
def htmltopdf(self str_html article_name):
info = self.courseInfo()
dirkName = info[‘courseName‘]
time.sleep(1)
dir = os.path.abspath(os.curdir)+‘\\resources\\‘+dirkName+‘\\‘
res = self.mkdir(dir)
path_wk = r‘C:\Users\male\Desktop\wkhtmltox-0.12.6-1.mxe-cross-win64 (1)\wkhtmltox\bin\wkhtmltopdf.exe‘
config = pdfkit.configur
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2020-08-25 17:26 csdn\
文件 5338 2020-08-25 17:37 csdn\pdf.py
文件 1046 2020-08-26 10:25 csdn\README.md
文件 9904 2020-08-26 10:23 csdn\run.py
- 上一篇:isbn查询书籍详细信息2.0
- 下一篇:QT modbus串口调试程序
相关资源
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
- 量化交易(附python常见函数的使用方
- python 名字用字排行
评论
共有 条评论