Python爬取QQ音乐排行榜的代码
时间: 2023-12-25 18:23:01 浏览: 346
Python使用Beautiful Soup爬取豆瓣音乐排行榜过程解析
好的,这个问题可以回答。以下是Python爬取QQ音乐排行榜的代码:
```python
import requests
from bs4 import BeautifulSoup
# 发送请求,获取HTML页面内容
url = "https://y.qq.com/n/yqq/toplist/4.html"
response = requests.get(url)
html = response.text
# 用BeautifulSoup解析页面内容
soup = BeautifulSoup(html, "html.parser")
song_list = soup.find_all("li", class_="js_song")
# 遍历歌曲信息,提取歌曲名字和演唱者
for song in song_list:
song_name = song.find("div", class_="songname").text.strip()
singer = song.find("div", class_="singer").text.strip()
print(song_name, "-", singer)
```
希望能帮到你!
阅读全文