数学建模社区-数学中国
标题:
Python-追剧下载视频
[打印本页]
作者:
檀俾九
时间:
2021-1-19 10:25
标题:
Python-追剧下载视频
[code=python]#!/usr/bin/python
4 f3 \: i. `- D/ T2 \
# -*- coding: utf-8 -*-
) E2 v* Y4 J1 M7 E
; I) B8 u( e3 C) u
import threading
; @: O- W: j7 Z/ p {
from lxml import etree
- K) `+ H" t/ w& C! y9 D8 x' s; F
import requests
% [" x8 g5 Z2 |: B' }, O. T; c
from ctypes import windll
) b/ \0 {8 T8 l) t
, z7 }5 `. |* U' ?1 Z1 U! g
4 R2 _; f: _! f# \7 s; h
def getmidstring(html, start_str, end):
: l( K% ]: i' ^2 r+ f
start = html.find(start_str)
( ^8 O; h/ }+ @! t/ o$ f
if start >= 0:
' Q$ l; n. g1 z' K9 N
start += len(start_str)
$ w& J+ A6 n. r' g+ U( i: A: P
end = html.find(end, start)
- r9 m$ a7 b* K5 ], l! y/ w k6 X
if end >= 0:
& q8 |2 O- x5 Z. Y7 }' W
return html[start:end].strip()
/ r- i3 F- t1 t$ x7 L' K
* Y0 Y0 r. j f, Y( @' @0 e; Q
, i% e( C/ |1 I
def getleftstring(html, end):
$ m& d H+ J+ b+ a$ S; B/ [7 f/ z
end = html.find(end)
# @0 c [) t. ?$ X( D- O" m
if end >= 0:
) a3 @8 K. Z/ [$ I1 c. {
return html[0:end].strip()
, ~4 U; Q1 k" T% h1 z0 ~/ F
! Q0 \/ i# T3 A3 b& N
7 u; }% C" T8 O2 u$ E
def updata(i):
3 x5 o' ^: ?0 ^/ p- \5 |
req = requests.get("https://www.xxx.com/play/xxx-2-%s.html" % i)
1 d% }! a# m4 s, e! T* q* M. _) j
req.encoding = "utf-8"
/ i) {$ W* U6 B+ I. W8 [5 O
m3u8 = getmidstring(req.text, "var now=\"", "\"")
. x4 j- R2 v, L& Y0 }4 b; D' f
" T8 s3 j* l! f0 \3 k7 V0 u
html = etree.HTML(req.text)
6 [; Q* K4 N8 G @ b3 [! ?5 H6 y' l
title = html.xpath("//meta[@name=\"description\"]/@content")[0]
" |- {- r: t( V
title = getleftstring(title, ",")
5 Z6 A; ~6 T) ?. P2 V8 T1 g
print(title)
) r# x" D0 q8 v( T: K3 P
4 Y- ^# M, l+ d. m* R3 V; G! ^: v
cmd = "\"%s\" --workDir \"%s\" --saveName \"%s\" --enableDelAfterDone" % (
( c) k, d% b; B" y" i4 T' K6 P8 P
m3u8,
+ g7 W! `) _$ z! d, x
r"F:\xxx",
# h8 c/ Q- _9 E _: V: O2 [' O
title)
% F7 ~0 p) q- l9 W6 V" Q
print(cmd)
" x( {" h+ q8 L% H, l' g. Z, p
' l0 [+ }% P0 A7 T% B1 j; H/ O& b' H
dll = windll.LoadLibrary("Shell32.dll")
* i9 X1 Q, e6 ~- a
print(dll.ShellExecuteW(None,
" J1 x% \4 \; V/ A4 p5 ?2 Y y# Z! F: h
"open",
' I5 c: M. ?) e& n
r"D:\xxx.exe",
6 N7 V, v7 Q1 Q+ {/ j
cmd, None, 1))
1 V0 M6 n Q& V
/ U0 N K# a# W
' q2 W& k2 v& Y. z0 |
def cycle():
8 T8 E4 ^4 P8 N+ T1 \1 Z
for i in range(40):
% E- F7 O& o, f/ z
updata(i)
$ O: a" s/ N0 v7 V& `
/ N4 H2 W* g' L4 o7 Z7 c
! G. Q5 L1 T$ x: l
if __name__ == '__main__':
: ?- `1 M8 G$ b( N/ S
hThread = threading.Thread(target=cycle)
; D, Z: B7 M9 Q6 [4 X' Q
hThread.setDaemon(True)
8 S3 Y4 {3 q) A1 n
hThread.start()
1 ~: I- K' x2 ?0 X2 \/ Z( t" u$ b
hThread.join()
% ]- e% o% u$ M4 R U( J4 s# I/ X$ B+ }
[/code]
# ~# _# t7 ^. h% h7 V
8 h8 G+ x3 U. t" N( W
在线追剧又卡又慢!还不方便,写个Python脚本自动帮我缓存下~
- ]8 ~9 e5 M' Q }; c
$ Y. s, J6 P5 i+ [
; b8 E9 k. @+ u9 n1 e; T
转发自
派生社区
Python交流群:1047602540
G6 e8 {/ f! \1 r6 q
0 b2 O3 v: v, w$ w5 D/ T6 w2 P
( s+ r2 Y& |/ C
欢迎光临 数学建模社区-数学中国 (http://www.madio.net/)
Powered by Discuz! X2.5