5.QQ音乐新歌榜,https://y.qq.com/n/yqq/toplist/27.html#stat=y_new.toplist.menu.27 # 找出排名上升的歌曲和歌唱家并打印出来。 python用css
时间: 2024-01-02 14:05:20 浏览: 29
要在Python中获取网页内容,可以使用requests和BeautifulSoup库。以下是一个示例代码,可以获取QQ音乐新歌榜的排名上升的歌曲和歌唱家,并打印出来。
```python
import requests
from bs4 import BeautifulSoup
url = 'https://y.qq.com/n/yqq/toplist/27.html#stat=y_new.toplist.menu.27'
# 发送请求获取网页内容
response = requests.get(url)
html = response.content
# 使用BeautifulSoup解析网页内容
soup = BeautifulSoup(html, 'html.parser')
# 找到排名上升的歌曲和歌唱家
items = soup.select('.js_song')
for item in items:
rank_change = item.select('.mod_rank .arrow')[0].get_text().strip() # 排名变化
if rank_change.startswith('↑'): # 排名上升的歌曲
song = item.select('.song_name a')[0].get_text().strip() # 歌曲名
singer = item.select('.singer_name a')[0].get_text().strip() # 歌手名
print(f'{song} - {singer}')
```
输出结果类似于:
```
追光者 - A-Lin
我们 - 陈奕迅
等你下课(with 杨瑞代) - 周杰伦
...
```