数学建模社区-数学中国
标题:
Python-追剧下载视频
[打印本页]
作者:
檀俾九
时间:
2021-1-19 10:25
标题:
Python-追剧下载视频
[code=python]#!/usr/bin/python
- x) Y& q; X4 N5 M2 \3 q6 F) c
# -*- coding: utf-8 -*-
+ j7 B/ N! h5 R7 D3 C
. _7 v( h m5 Z7 R: a5 H0 t0 h
import threading
9 d5 U8 s( l% `7 x- T( ~. a4 \
from lxml import etree
' i) Q2 `1 [: `
import requests
0 @& Y$ w/ ]# X
from ctypes import windll
' f, i1 _6 a" K. c% Z1 D
+ u, k5 Z" |0 T# U6 h6 D
/ r H3 ^. `+ y6 Z2 n% |8 i
def getmidstring(html, start_str, end):
9 g" n/ F' V W/ v
start = html.find(start_str)
" C, P$ a; M6 R3 R( X# m6 l9 F3 a4 z
if start >= 0:
{' y2 Y# m/ k6 h& ^' |
start += len(start_str)
6 A* B8 Z Y# F
end = html.find(end, start)
$ \% {; Z o, T- f- ^4 D4 h8 M
if end >= 0:
$ M: H8 `8 X9 V
return html[start:end].strip()
& ^/ F5 K: e' X
+ R1 u" i) {: T; ]4 P& @; X
: h U0 {7 ` L- J; u4 H$ |+ Z; n* k
def getleftstring(html, end):
. {# `9 H$ P; O9 V* N% b& P1 D
end = html.find(end)
& M/ Y3 z6 S& T0 w7 r
if end >= 0:
7 a0 b* R; U) H1 z |
return html[0:end].strip()
, e6 l- P5 q, G( H
7 f( d" ~% _* a
/ P3 Q+ g+ y4 k& F
def updata(i):
% U9 b, q2 Z! e! g) p" Y/ t& y
req = requests.get("https://www.xxx.com/play/xxx-2-%s.html" % i)
& \4 Y- [/ U, c7 E! j
req.encoding = "utf-8"
+ @( M! ~$ \- z `! G
m3u8 = getmidstring(req.text, "var now=\"", "\"")
, ]9 M! w# }* ~2 y
( x' G' Q- V) W5 {
html = etree.HTML(req.text)
: w0 U) S5 c3 F$ F( _
title = html.xpath("//meta[@name=\"description\"]/@content")[0]
) H! }; r @4 f- k4 B' K. U
title = getleftstring(title, ",")
4 E" o( c! b; q
print(title)
. W8 N. N' L4 D3 h v. I* [+ F3 [2 r
* b' N- }6 x4 {, q/ o% o8 c g9 E" \
cmd = "\"%s\" --workDir \"%s\" --saveName \"%s\" --enableDelAfterDone" % (
. y% ~$ x/ S1 c/ k# z
m3u8,
7 U/ a/ V$ l( L6 v: z
r"F:\xxx",
$ ~- ~6 k3 w* S
title)
& ^) @' K: Z; m3 \& j4 T
print(cmd)
5 e* d) ]2 }6 l0 a: c# _0 F
/ L5 O9 d* U4 f) T; g
dll = windll.LoadLibrary("Shell32.dll")
/ q# ]% D G- i5 v: u
print(dll.ShellExecuteW(None,
" W3 [! K% U& c4 n7 J+ v# R# U' u
"open",
5 O! T$ {4 V3 ^1 ?
r"D:\xxx.exe",
8 ~# w4 A4 T% W/ |3 a3 v: V. \
cmd, None, 1))
& g- O$ C; W' G8 w( \1 d. ?4 a
5 u- V0 S* L6 O
: @- [/ l, f4 e \- T) v
def cycle():
" j. n& J; M6 n# }9 b9 ]
for i in range(40):
* K) h* u% X8 m% o
updata(i)
6 ~, @( p9 }% E% \
! a# E& b0 z7 N8 t8 N' Y/ h9 `& d
$ ]# o t6 y" C4 N) v% c% T
if __name__ == '__main__':
; L3 g; k4 `4 x
hThread = threading.Thread(target=cycle)
% h+ |2 h/ k$ P3 t; i
hThread.setDaemon(True)
. q/ P0 k& a' H+ x) w) b+ F [
hThread.start()
9 U4 v4 J* }3 [! P6 M
hThread.join()
/ [8 O$ _, p& l. z2 n
[/code]
- n% g; w$ {7 h. c6 |5 D
; W$ I! i0 x* r/ }! [: l9 D k- f! l
在线追剧又卡又慢!还不方便,写个Python脚本自动帮我缓存下~
7 k- K. l; d) j" \" s6 P
0 f. z2 }& F" ]) G
. w# E+ [9 ~8 V, K \
转发自
派生社区
Python交流群:1047602540
2 S9 v5 B2 t- }" d, D
1 a: T) s- `% Z5 K1 |9 V* {2 m' l i
3 C9 u. H/ _5 ?: F
欢迎光临 数学建模社区-数学中国 (http://www.madio.net/)
Powered by Discuz! X2.5