From 6a560a65005c4e3fa8cbb12a04206bd22d5702f6 Mon Sep 17 00:00:00 2001 From: pgsj7zf8t <3585596421@qq.com> Date: Wed, 12 Jun 2024 15:35:38 +0800 Subject: [PATCH] ADD file via upload --- music.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 music.py diff --git a/music.py b/music.py new file mode 100644 index 0000000..04df920 --- /dev/null +++ b/music.py @@ -0,0 +1,50 @@ +import re +import csv +import requests +from lxml import etree +from bs4 import BeautifulSoup + +url = 'https://music.163.com/discover/toplist?id=3778678' +headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " + "(KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0"} +down_url = 'https://music.163.com/song/media/outer/url?id=' + +# 发送请求 +response = requests.get(url, headers=headers) + +# 获取数据 +html_data = response.text + +# 解析数据 +soup = BeautifulSoup(html_data, 'lxml') + +# 创建一个空的列表来存储爬取的数据 +song_data = [] + +# 爬取歌名、ID和url +song_list = re.findall('