From c1eda83da4a0212f8ba85750a163f8534d92134d Mon Sep 17 00:00:00 2001 From: pmpk7fa3w <18879448683@163.com> Date: Tue, 18 Jun 2024 22:09:50 +0800 Subject: [PATCH] ADD file via upload --- 1.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 1.py diff --git a/1.py b/1.py new file mode 100644 index 0000000..7a7a6ae --- /dev/null +++ b/1.py @@ -0,0 +1,28 @@ +import csv + +import requests +import bs4 +import lxml +url="https://www.kugou.com/yy/rank/home/1-49224.html?from=rank" +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.' +} +r = requests.get(url, headers=headers) +# print(r.text) +bea = bs4.BeautifulSoup(r.text,"lxml") +html = bea.select("div.pc_temp_songlist>ul>li") +html1 = bea.select("span.pc_temp_time") +html2 = bea.select("a.pc_temp_songname") +text = [] +for i in range(0,len(html)): + a = [] + a.append(html[i].get("title")) + a.append(html1[i].get_text(strip=True)) + a.append(html2[i].get("href")) + text.append(a) +with open("酷狗音乐.csv","a",encoding="utf-8",newline="") as f : + w = csv.writer(f) + w.writerow(["歌名","时长","链接"]) +with open("酷狗音乐.csv","a",encoding="utf-8",newline="") as f : + w = csv.writer(f) + w.writerows(text) \ No newline at end of file