爬虫 网易云音乐热歌榜的歌曲名 代码
时间: 2024-03-28 20:32:01 浏览: 112
python爬取网易云音乐热歌榜实例代码
5星 · 资源好评率100%
以下是爬取网易云音乐热歌榜歌曲名的代码示例:
```python
import requests
from bs4 import BeautifulSoup
def get_all_hotSong():
url = 'http://music.163.com/discover/toplist?id=3778678'
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.find('ul', class_='f-hide').find_all('a')
hot_song_name = []
hot_song_id = []
for song in song_list:
hot_song_name.append(song.text)
hot_song_id.append(song['href'].split('=')[-1])
return hot_song_name, hot_song_id
hot_song_name, hot_song_id = get_all_hotSong()
print("热歌榜歌曲名:", hot_song_name)
```
阅读全文