-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBaiduNetDiskParser.py
65 lines (52 loc) · 1.67 KB
/
BaiduNetDiskParser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Author: lsy
# @Date&Time: 2019/12/17 15:36
# @Description: 百度网盘链接解析
import logging
from html.parser import HTMLParser
class BaiduNetDiskParser(HTMLParser):
def __init__(self):
HTMLParser.__init__(self)
self.__is_span = False
self.__is_font = False
self.__href = None
self.__code = None
def handle_starttag(self, tag, attrs):
if tag == 'span':
for attr in attrs:
if attr[0] == 'class' and attr[1] == 'downfile':
self.__is_span = True
self.__is_font = False
return
elif tag == 'a':
if self.__is_span:
self.__is_span = False
self.__is_font = False
for attr in attrs:
if attr[0] == 'href':
self.__href = attr[1]
logging.info(self.__href)
return
elif tag == 'font':
self.__is_span = False
for attr in attrs:
if attr[0] == 'style' and attr[1] == 'color: #7B68EE;font-weight: bold;':
self.__is_font = True
return
self.__is_span = False
self.__is_font = False
def handle_data(self, data):
if self.__is_font:
data = data.strip()
if data:
self.__code = data
logging.info(self.__code)
@property
def href(self):
return self.__href
@property
def code(self):
return self.__code
def error(self, message):
logging.info(message)