python爬取qq音乐代码
时间: 2023-09-18 18:14:35 浏览: 146
python爬取音乐
你好,以下是获取QQ音乐排行榜信息的Python代码:
```python
import requests
from bs4 import BeautifulSoup
url = 'https://y.qq.com/n/yqq/toplist/4.html'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.63 Safari/537.36'
}
res = requests.get(url, headers=headers)
soup = BeautifulSoup(res.text, 'html.parser')
songlist = soup.select('.songlist__list li')
for song in songlist:
title = song.select('a.songlist__title')[0].text
singer = song.select('a.songlist__artist')[0].text
print(title + '-' + singer)
```
希望对你有所帮助!
阅读全文