Skip to content

Commit 9e377d7

Browse files
author
mochazi
committed
2022-01-27 下载荔枝微课-mitmproxy版本🎉
1 parent ab6da82 commit 9e377d7

File tree

7 files changed

+158
-0
lines changed

7 files changed

+158
-0
lines changed

下载荔枝微课/ffmpeg.exe

10.9 MB
Binary file not shown.

下载荔枝微课/request_demo.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# python 3.7
2+
import mitmproxy.http,json,os,requests
3+
from mitmproxy import ctx
4+
from pathlib import Path
5+
6+
'''
7+
本次爬取的课程地址:https://m.lizhiweike.com/channel2/1192275
8+
'''
9+
10+
cookie = '请填写你的Cooie'
11+
filename = None # 下载视频路径
12+
current_filename = os.getcwd().replace('\\','/') # 获取当前路径
13+
title = None # 标题
14+
15+
class Counter:
16+
17+
def __init__(self):
18+
self.Referer = 'https://m.lizhiweike.com/channel2/1192275'
19+
self.UserAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36'
20+
self.headers = {
21+
'Referer':self.Referer,
22+
'Host':'m.lizhiweike.com',
23+
'User-Agent':self.UserAgent
24+
}
25+
26+
def request(self, flow: mitmproxy.http.HTTPFlow):
27+
28+
# 所有请求插入协议头
29+
flow.request.headers['Referer'] = self.Referer
30+
31+
def response(self, flow: mitmproxy.http.HTTPFlow):
32+
33+
# 导入全局变量
34+
global filename,title,current_filename,cookie
35+
36+
if 'lecture' in flow.request.url and 'info' in flow.request.url:
37+
38+
# 加载 JSON 对象
39+
json_data = json.loads(flow.response.text)
40+
41+
try:
42+
# 获取当前视频标题
43+
title = json_data['data']['share_info']['share_title'].replace(' ','')
44+
except:
45+
pass
46+
47+
# 获取课程标题
48+
if 'qcvideo' in flow.request.url:
49+
50+
# 加载 JSON 对象
51+
json_data = json.loads(flow.response.text)
52+
53+
# 获取视频URL
54+
video_url = json_data['data']['play_list'][0]['url']
55+
56+
print(f'【信息】当前视频标题:{title},视频mp4链接:{video_url}')
57+
58+
# 如果没有文件夹,就创建文件夹
59+
filename = current_filename + '/下载成功的视频/'
60+
if not os.path.exists(filename):
61+
os.makedirs(filename)
62+
63+
# 生产mp4存放路径
64+
mp4_filename_path = f'{filename}{title}.mp4'
65+
66+
headers = {
67+
'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36',
68+
'referer':'https://m.lizhiweike.com/channel2/1192275',
69+
'Cookie':cookie
70+
}
71+
72+
# 下载视频
73+
html = requests.get(url=video_url,headers=headers)
74+
with open(mp4_filename_path,'wb') as f:
75+
f.write(html.content)
76+
77+
addons = [
78+
Counter()
79+
]

下载荔枝微课/requirements.txt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
asgiref==3.3.4
2+
beautifulsoup4==4.9.3
3+
blinker==1.4
4+
Brotli==1.0.9
5+
bs4==0.0.1
6+
certifi==2021.5.30
7+
cffi==1.14.6
8+
charset-normalizer==2.0.3
9+
click==7.1.2
10+
cryptography==3.2.1
11+
Flask==1.1.4
12+
h11==0.12.0
13+
h2==4.0.0
14+
hpack==4.0.0
15+
hyperframe==6.0.1
16+
idna==3.2
17+
iso8601==0.1.14
18+
itsdangerous==1.1.0
19+
Jinja2==2.11.3
20+
kaitaistruct==0.9
21+
ldap3==2.8.1
22+
m3u8==0.9.0
23+
MarkupSafe==2.0.1
24+
mitmproxy==5.3.0
25+
msgpack==1.0.2
26+
passlib==1.7.4
27+
protobuf==3.13.0
28+
publicsuffix2==2.20191221
29+
pyasn1==0.4.8
30+
pycparser==2.20
31+
pycryptodome==3.10.1
32+
pydivert==2.1.0
33+
pyOpenSSL==19.1.0
34+
pyparsing==2.4.7
35+
pyperclip==1.8.2
36+
requests==2.26.0
37+
ruamel.yaml==0.16.13
38+
ruamel.yaml.clib==0.2.6
39+
selenium==3.141.0
40+
six==1.16.0
41+
sortedcontainers==2.2.2
42+
soupsieve==2.2.1
43+
tornado==6.1
44+
typing-extensions==3.10.0.0
45+
urllib3==1.26.6
46+
urwid==2.1.2
47+
Werkzeug==1.0.1
48+
wsproto==0.15.0
49+
zstandard==0.14.1
Binary file not shown.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from selenium import webdriver
2+
3+
PROXY='http://127.0.0.1:8080'
4+
5+
chrome_options = webdriver.ChromeOptions()
6+
chrome_options.add_argument("--proxy-server=127.0.0.1:8080")
7+
chrome_options.add_experimental_option('excludeSwitches', ['enable-automation']) # 专业模式
8+
9+
10+
browser = webdriver.Chrome(executable_path=r'chromedriver.exe',options=chrome_options)#r 代表的是强制禁止转义
11+
12+
'''
13+
本次爬取的课程地址:https://m.lizhiweike.com/channel2/1192275
14+
'''
15+
16+
url = 'https://m.lizhiweike.com/channel2/1192275'
17+
browser.get(url)#访问网站
18+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
�ȴ�һ��cmd������mitmweb -s request_demo.py
2+
Ȼ����cd����selenium�����ļ��У�����python selenium_start.py
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
一次性安装
2+
pip install -r requirements.txt -i https://pypi.mirrors.ustc.edu.cn/simple
3+
4+
分开安装
5+
pip install mitmproxy
6+
pip install selenium
7+
pip install m3u8
8+
pip install requests
9+
pip install bs4
10+
pip install pycryptodome

0 commit comments

Comments
 (0)