-
-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathtestxpath.py
63 lines (53 loc) · 2.08 KB
/
testxpath.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2023/02/21
@author: Irony
@site: https://pyqt.site https://github.com/PyQt5
@email: [email protected]
@file: testxpath.py
@description:
"""
import os
from lxml.etree import HTML # @UnresolvedImport
# 作者
Actor = '''<a href="{href}" target="_blank" title="{title}" style="text-decoration: none;font-size: 12px;color: #999999;">{title}</a> '''
def _makeItem(lis):
for li in lis:
a = li.find('.//div/a')
play_url = "https://music.163.com" + a.get("href") # 视频播放地址
img = li.find(".//div/img")
cover_url = img.get("src") # 封面图片
playlist_title = a.get("title") # 歌单名
# figure_info = a.find("div/span")
figure_info = "aaa" #if figure_info is None else figure_info.text # 影片信息
figure_score = "" # 评分
# 歌手
figure = li.xpath(".//p[2]/a")[0]
playlist_author = "<span style=\"font-size: 12px;\"作者:{}</span>".format(
Actor.format(href="https://music.163.com" +figure.get("href"),title=figure.get("title")))
# 播放数
play_count = (li.xpath(".//div/div/span[2]/text()") or [""])[0]
path = "cache/{0}.jpg".format(
os.path.splitext(os.path.basename(cover_url).split('?')[0])[0])
cover_path = "Data/pic_v.png"
if os.path.isfile(path):
cover_path = path
print(cover_path, playlist_title, playlist_author,
play_count, play_url, cover_url, path)
# iwidget = ItemWidget(cover_path, playlist_title,
# playlist_author, play_count, play_url,
# cover_url, path, self)
# self._layout.addWidget(iwidget)
def _parseHtml(html):
html = HTML(html)
# 查找所有的li
lis = html.xpath("//ul[@id='m-pl-container']/li")
# if not lis:
# self.Page = -1 # 后面没有页面了
# return
# self.Page += 1
_makeItem(lis)
if __name__ == '__main__':
data = open(r'D:\Computer\Desktop\163.html', 'rb').read()
_parseHtml(data)