数学建模社区-数学中国

标题: Python-追剧下载视频 [打印本页]

作者: 檀俾九    时间: 2021-1-19 10:25
标题: Python-追剧下载视频
[code=python]#!/usr/bin/python' B. f5 T4 f2 G+ b5 [
# -*- coding: utf-8 -*-# z: L6 a" [+ }7 R+ Q

) e: o, F1 L# U* Bimport threading
9 l, S3 b0 a8 h) \3 h9 n. Bfrom lxml import etree% H  o2 z' u1 ?3 e6 p3 C. ?) U
import requests8 c1 }$ _! d' B7 i+ E  O4 G
from ctypes import windll2 A# H, m% k- o
6 S* a- r' g  X$ l) u
* a. z4 h# [+ K: h" |
def getmidstring(html, start_str, end):+ J  z! j7 X6 ]6 B
    start = html.find(start_str)  a' F, _: x+ x8 F
    if start >= 0:
) a/ [, `* ^; X* g2 W& w1 _' }        start += len(start_str)( G  {6 O- D+ \1 K# Y
        end = html.find(end, start)
8 @9 |) D3 B& g% [        if end >= 0:& ~2 j& y. ^! b. {, E+ Z3 L( ^
            return html[start:end].strip()
& t1 V! K" R* |% W' k5 N" W
3 O! @0 n3 U2 l8 q$ o2 s
4 u) G; a! W! p$ u+ c5 N" Mdef getleftstring(html, end):5 b7 l: }; t; k/ m+ X# x
    end = html.find(end)
& I3 ]" L4 V: n4 M, [. l    if end >= 0:
( B: h( u; t2 M- s" ~  M: N        return html[0:end].strip()8 q" V. v# H8 R) ]4 T
9 a0 k5 n! R5 L! k" M; n) Y5 I
) {9 m/ S2 @. ^
def updata(i):
6 q6 }; K! h( b+ ^    req = requests.get("https://www.xxx.com/play/xxx-2-%s.html" % i)1 p( `7 u0 }; ]3 r8 e
    req.encoding = "utf-8"
  x$ I/ U& ^- S, c, [& a; @& h6 u    m3u8 = getmidstring(req.text, "var now=\"", "\"")
8 ^1 N. V5 Z, B+ U2 D
) C: M- ~" R+ F3 O) X    html = etree.HTML(req.text)' a( |2 q; I) p' S9 n, @
    title = html.xpath("//meta[@name=\"description\"]/@content")[0]( q, M. q* _1 M7 j& d! n" L" x
    title = getleftstring(title, ",")
6 z* R, q3 |+ e: `3 S+ e2 N5 i& C; |' w    print(title)
) D0 t' r# H6 x) n" T" L8 X( B6 A; R0 F5 f% T
    cmd = "\"%s\" --workDir \"%s\" --saveName \"%s\" --enableDelAfterDone" % (8 ~. J2 A; }& Z$ z
        m3u8,; _8 m) O3 ~5 }& U9 i+ O+ a
        r"F:\xxx",
: [" T6 ~7 r7 H0 b        title)
6 g* v/ |# U  O9 v% J# B    print(cmd)9 K' M& n2 d2 {4 u
2 o2 g. o+ M. Q
    dll = windll.LoadLibrary("Shell32.dll")3 e* d5 q& V7 @& w, U
    print(dll.ShellExecuteW(None,4 h' `9 s% n* Z' s+ H
                            "open",
& c8 J0 ?& z3 X* z- A: i( \                            r"D:\xxx.exe",
$ T- P, k! ^/ G+ S! B$ j8 L                            cmd, None, 1))
- C* t0 a, G7 R+ y( C( I" Q) L1 k5 ~! Q2 ~0 D  V0 h
5 }2 H' T+ p. Q1 |
def cycle():
; @2 u1 ?$ \7 J4 Q+ j7 H+ u    for i in range(40):
- C/ K0 Z+ K3 [- [        updata(i)
4 t4 `$ W7 @4 e5 |8 Z: ?" N7 U/ m, b! h8 q+ h  A

# L0 O) z" ]( H3 Pif __name__ == '__main__':7 M* d% o  V& \' x
    hThread = threading.Thread(target=cycle)% h! D6 C3 S: U) w, ?
    hThread.setDaemon(True)
& E* g% R* \+ U- v    hThread.start(). a) I. {& N% W2 G1 [
    hThread.join(): S1 J& S( r8 P2 F  ?( ]  N" Z
[/code]0 L  ]5 _9 N/ V5 r& e8 R0 j+ B. g4 Y

3 f5 @* V+ V! m8 Z# m在线追剧又卡又慢!还不方便,写个Python脚本自动帮我缓存下~
+ O6 Q$ s  E6 {. P- i1 I+ F# a& j  t; T

" ?+ m( y, e' p5 y7 i
转发自派生社区
Python交流群:1047602540

$ W: T. ^5 V  p- B
! O2 U+ y! k5 |
( h: I! E- L) {0 L! p3 e* P2 N% m) [




欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) Powered by Discuz! X2.5