修复第三方无法抓取的问题

This commit is contained in:
shaonianzhetnan 2023-08-13 00:37:01 +08:00
parent b48ff0f723
commit d3bcadf7c1
2 changed files with 9 additions and 8 deletions

View File

@ -1,7 +1,7 @@
{
"domain": "ha_cloud_music",
"name": "\u4E91\u97F3\u4E50",
"version": "2023.7.18",
"version": "2023.8.13",
"config_flow": true,
"documentation": "https://github.com/shaonianzhentan/ha_cloud_music",
"requirements": [

View File

@ -9,26 +9,27 @@ def get_music(keyword):
try:
response = session.get(f'{api}/s/{keyword}')
soup = BeautifulSoup(response.text.encode(response.encoding), 'lxml')
items = soup.select('.table tbody tr')
if len(items) > 0:
td = items[0].select('td')
items = soup.select('.card-text .row')
if len(items) > 1:
row = items[1]
# print(td)
song = td[0].get_text().strip()
singer = td[1].get_text().strip()
song = row.select('.col-5 a')[0].get_text().strip()
singer = row.select('.col-4')[0].get_text().strip()
a = items[0].select('a')
a = row.select('.col-3 a')
href = a[0].attrs['href']
# print(href)
response = session.get(f'{api}{href}')
html = response.text
pattren = re.compile(r'https://[^\s]+.mp3')
url_lst = pattren.findall(html)
# print(url_lst)
if len(url_lst) > 0:
soup = BeautifulSoup(html, 'lxml')
cover = soup.select('head meta[property="og:image"]')
print(cover)
#print(cover)
pic = 'https://p2.music.126.net/tGHU62DTszbFQ37W9qPHcg==/2002210674180197.jpg'
# 封面
if len(cover) > 0: