python爬取网易云音乐飙升榜音乐_python爬取网易云音乐热歌榜 python爬取网易云音乐热歌榜实例代码...
时间: 2023-07-21 11:37:00 浏览: 89
好的,以下是Python爬取网易云音乐热歌榜的实例代码:
```python
import requests
from bs4 import BeautifulSoup
url = 'https://music.163.com/discover/toplist?id=3778678' # 网易云音乐热歌榜的URL
headers = {
'Referer': 'https://music.163.com/',
'Host': 'music.163.com',
'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.find('ul', class_='f-hide').find_all('a') # 获取歌曲列表
for song in song_list:
print(song.text) # 输出歌曲名称
```
运行上述代码,即可爬取网易云音乐热歌榜的歌曲列表。同理,如果要爬取飙升榜的歌曲列表,只需将URL改为`'https://music.163.com/discover/toplist?id=19723756'`即可。