【问题标题】:How do I build a Python program with the iTune ssearch service如何使用 iTunes 搜索服务构建 Python 程序
【发布时间】:2022-12-25 04:10:35
【问题描述】:

我是 Python 的新手,我被要求编写一个程序,要求用户输入搜索词,然后使用 iTunes 搜索服务对实体类型专辑执行搜索。然后程序应该打印返回了多少搜索结果。对于每个结果,打印艺术家姓名、专辑名称和曲目数。我应该使用 get() 函数和 json() 方法。

有人可以让我走上正确的道路吗?我对这个程序感到迷茫。

【问题讨论】:

  • 请先尝试一些事情,然后将您的问题与您的代码、错误一起发布。
  • 我不知道从哪里开始。让我问一下...我如何使用 iTunes 搜索服务执行搜索?这是我应该访问的图书馆吗?

标签: python json get itunes-search-api


【解决方案1】:

琳达,我想我们在同一个 OpenSAP 班级……这应该让你继续。

import json
import requests as r

x = input("Please enter a search term: ")
url = f'https://itunes.apple.com/search?term={x}&entity=album' 
r = r.get(url) 

print(f"The search returned {r.text.count(x)} results."

【讨论】:

    【解决方案2】:
    import requests as r
    Count = 0
    artist = ""
    album = ""
    trackcount = 0
    x = input("Please enter a search term: ")
    url = f"https://itunes.apple.com/search?term={x}&entity=album"
    f = r.get(url) 
    d = f.json()
    for x in d:
        if x == "resultCount":
            count = d["resultCount"]
            print(f"The search returned {str(count)} results.")
        elif x == "results":
            for lx in d["results"]:
                artist = lx["artistName"]
                album = lx["collectionName"]
                trackcount = lx["trackCount"]
                print(f"Artist: {artist} - Album: {album} - Track Count: {str(trackcount)}")
    

    【讨论】:

      【解决方案3】:

      pip 安装 iGetMusic

      iGetMusic.get(term="SEARCH TERM")

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-28
        • 1970-01-01
        • 2020-02-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多