1

没有太多成功,我一直在尝试从某个类别的所有帖子中检索图像(和摘录)。

这是从主页获取图像的查询,但我没有找到特定类别的查询。

api.php?action=query&prop=images&titles=Main%20Page

使用搜索似乎更有希望,但它仍然不是我想要的。

api.php?action=query&list=search&format=jsonfm&srsearch=incategory:Marine_mammals

如果第二个查询提供了页面 ID,那么它可能是一个很好的起点。

4

1 回答 1

2

你想要的是使用categorymembers生成器,通过添加&generator=categorymembers&gcmtitle=Category%3AMarine_mammals代替&titles. 自从我发现生成器后,我几乎不记得将 API 用于其他任何事情。我还建议坚持使用 mainspace。例如,

https://en.wikipedia.org/w/api.php?action=query&prop=images&format=json&imlimit=10&generator=categorymembers&gcmtitle=Category%3AMarine_mammals&gcmnamespace=0&gcmlimit=50

给出

{"query-continue":{"images":{"imcontinue":"60257|Ursus_maritimus_4_1996-08-04.jpg"}},"query":{"pages":{"149269":{"pageid": 149269,"ns":0,"title":"Blubber"},"19289045":{"pageid":19289045,"ns":0,"title":"Instituto Via Delphi"},"2178272":{ "pageid":2178272,"ns":0,"title":"澳大利亚海洋哺乳动物列表"},"60257":{"pageid":60257,"ns":0,"title":"海洋哺乳动物","images":[{"ns":6,"title":"File:Desmostylus2DB.jpg"},{"ns":6,"title":"File:Estuary-mouth.jpg"},{ "ns":6,"title":"文件:FL fig04.jpg"},{"ns":6,"title":"文件:座头鲸水下拍摄.jpg"},{"ns":6,"title":"文件:Hydrurga leptonyx edit1.jpg"},{"ns":6, "title":"File:Maldivesfish2.jpg"},{"ns":6,"title":"File:Oceanic whale pump - journal.pone.0013255.g001.tiff"},{"ns":6, "title":"File:PikiWiki Israel 15217 Dolphin.JPG"},{"ns":6,"title":"File:Sea lion family.JPG"},{"ns":6,"title":" File:Sea otter cropped.jpg"}]},"36425597":{"pageid":36425597,"ns":0,"title":"海洋哺乳动物作为食物"},"3703749":{"pageid": 3703749,"ns":0,"title":"水獭"},"644379":{"pageid":644379,"ns":0,"title":"北大西洋海洋哺乳动物委员会"},"1336536":{"pageid":1336536,"ns":0,"title":"海貂"},"567471": {"pageid":567471,"ns":0,"title":"海獭"},"2764345":{"pageid":2764345,"ns":0,"title":"美国海军海洋哺乳动物程序”}}}}美国海军海洋哺乳动物计划"}}}}美国海军海洋哺乳动物计划"}}}}

于 2013-08-01T21:53:30.510 回答