通过 Python 从 iTunes 前 100 名中获取歌曲名称和艺术家

Posted

技术标签:

【中文标题】通过 Python 从 iTunes 前 100 名中获取歌曲名称和艺术家【英文标题】:Get song name and artist from iTunes top 100 by Python 【发布时间】:2018-09-05 04:04:01 【问题描述】:

我对 Python Crawl 有点陌生,只想获取歌曲和艺术家。 Scrapy 肯定会更容易做到这一点,但我想尝试使用 requests 和 bs4。

我知道我需要从这里获取数据:https://itunes.apple.com/us/rss/topsongs/limit=100/json

数据对我来说看起来很复杂,如果有人能指出正确的方向,我将不胜感激。

最好的,

【问题讨论】:

【参考方案1】:

你真的不想用漂亮的汤,因为你有 json 数据。 你只需要请求。

import requests

url = 'https://itunes.apple.com/us/rss/topsongs/limit=100/json'

response = requests.get(url)

data = response.json()

for artist_dict in data['feed']['entry']:
    artist_name = artist_dict['im:artist']['label']
    song_artist = artist_dict['title']['label']
    print(artist_name)

【讨论】:

您在哪里找到的网址?它没有记录在任何地方,但它可以工作

以上是关于通过 Python 从 iTunes 前 100 名中获取歌曲名称和艺术家的主要内容,如果未能解决你的问题,请参考以下文章