生成一段python爬虫酷狗音乐代码
时间: 2023-04-03 15:03:53 浏览: 183
以下是一段简单的 Python 爬虫酷狗音乐的代码,供参考:
```python
import requests
from bs4 import BeautifulSoup
url = 'http://www.kugou.com/yy/rank/home/1-8888.html?from=rank'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.text, 'html.parser')
song_list = soup.select('.pc_temp_songlist > ul > li')
for song in song_list:
rank = song.select('span.pc_temp_num')[0].text.strip()
name = song.select('a')[0].text.strip()
singer = song.select('a')[1].text.strip()
album = song.select('a')[2].text.strip()
print(rank, name, singer, album)
```
希望能对你有所帮助。
阅读全文