维基百科API信息缺失的问题

问题描述 投票:0回答:1

这是我在StackOverflow上的第一个问题,如果我做错了什么,请告诉我......

我一直在做一些webscraping,特别是在寻找所有的 "类别",某些音乐团体属于维基百科。我还是个新手,所以我可能忽略了一些非常基本的东西......。

为此我使用了维基百科的API。它对一些乐队的效果很好。例如,如果我寻找Maroon 5

r = http.get("https://en.wikipedia.org/w/api.php?action=query&format=json&prop=categories&titles=Maroon_5")
r.json()

它返回这个JSON文件

{'continue': {'clcontinue': '512449|Articles_with_permanently_dead_external_links',
  'continue': '||'},
 'query': {'normalized': [{'from': 'Maroon_5', 'to': 'Maroon 5'}],
  'pages': {'512449': {'pageid': 512449,
    'ns': 0,
    'title': 'Maroon 5',
    'categories': [{'ns': 14,
      'title': 'Category:1994 establishments in California'},
     {'ns': 14, 'title': 'Category:222 Records artists'},
     {'ns': 14, 'title': 'Category:A&M Records artists'},
     {'ns': 14, 'title': 'Category:Adam Levine'},
     {'ns': 14,
      'title': 'Category:All Wikipedia articles needing words, phrases or quotes attributed'},
     {'ns': 14, 'title': 'Category:All articles with dead external links'},
     {'ns': 14, 'title': 'Category:American pop rock music groups'},
     {'ns': 14, 'title': 'Category:American soul musical groups'},
     {'ns': 14,
      'title': 'Category:Articles with dead external links from February 2020'},
     {'ns': 14, 'title': 'Category:Articles with hCards'}]}}}}

但对于很多其他的频段,比如 "Active Child",这个文件会被返回。

r = requests.get("https://en.wikipedia.org/w/api.php?action=query&format=json&prop=categories&titles=Acid_Casuals")
r.json()
{'batchcomplete': '',
 'query': {'pages': {'-1': {'ns': 0, 'title': 'Acid Casuals', 'missing': ''}}}}

我试过把"%20 "换成"_",但没有任何变化。谁能告诉我这是怎么回事,如何解决?

另外,我还注意到,即使是Maroon 5,也有很多类别在json中丢失。这可能是一个相关的问题,我猜测。

如果所有其他方法都失败的话,我会尝试深入研究Beautifulsoup,但我还是更希望这个方法能够成功。

非常感谢你的帮助

python api web-scraping wikipedia-api
1个回答
1
投票

英文维基百科确实有一篇名为 Maroon 5 但没有任何文章标题 酸性休闲装. 该 'missing' 关键在反应是一个指标。没有文章,没有类别。

© www.soinside.com 2019 - 2024. All rights reserved.