维基百科API混乱云:"列表"与"生成器"与"搜索"



我的目标是编写一个维基百科的API搜索,它将:

  • 仅在"英语电影"类别中返回页面
  • 其中,返回仅以字母"Avatar"开头的页面(或者任何东西,真的,只是用这些字母作为示例)
  • 其中,给我网址,
  • 标题,日期,摘要和主页图像。

到目前为止,我已经尝试了三件事,似乎没有一件事能够完全做到我想要的。


问题:list=allpages通常无用

以下是list=allpages搜索:

https://en.wikipedia.org/w/api.php?action=query&format=json&prop=info%7Cpageimages%7Cextracts&list=allpages&inprop=url%7Cdisplaytitle&piprop=name%7Cthumbnail%7Coriginal&pithumbsize=100&exintro=1&explaintext=1&apprefix=Avatar&aplimit=3

这是结果(仅前 3 页):

{
"batchcomplete": "",
"continue": {
"apcontinue": "Avatar,_The_Last_Airbender",
"continue": "-||info|pageimages|extracts"
},
"query": {
"allpages": [
{
"pageid": 100368,
"ns": 0,
"title": "Avatar"
},
{
"pageid": 4846971,
"ns": 0,
"title": "Avatar's Abode"
},
{
"pageid": 35243953,
"ns": 0,
"title": "Avatar, Iran"
}
]
}
}

如您所见,它基本上忽略了我的所有prop请求。


问题:generator=allpages无法按类别搜索

以下是使用generator-allpages进行搜索:

https://en.wikipedia.org/w/api.php?action=query&format=json&prop=info%7Cpageimages%7Cextracts&generator=allpages&inprop=url%7Cdisplaytitle&piprop=name%7Cthumbnail%7Coriginal&pithumbsize=100&exintro=1&explaintext=1&gapprefix=Avatar

这是它的输出(只是第一个结果):

{
"batchcomplete": "",
"continue": {
"gapcontinue": "Avatar's_Abode",
"continue": "gapcontinue||"
},
"query": {
"pages": {
"100368": {
"pageid": 100368,
"ns": 0,
"title": "Avatar",
"contentmodel": "wikitext",
"pagelanguage": "en",
"pagelanguagehtmlcode": "en",
"pagelanguagedir": "ltr",
"touched": "2018-05-03T11:21:07Z",
"lastrevid": 838959509,
"length": 45784,
"fullurl": "https://en.wikipedia.org/wiki/Avatar",
"editurl": "https://en.wikipedia.org/w/index.php?title=Avatar&action=edit",
"canonicalurl": "https://en.wikipedia.org/wiki/Avatar",
"displaytitle": "Avatar",
"thumbnail": {
"source": "https://upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Avatars.jpg/80px-Avatars.jpg",
"width": 80,
"height": 100
},
"original": {
"source": "https://upload.wikimedia.org/wikipedia/commons/a/a0/Avatars.jpg",
"width": 357,
"height": 448
},
"pageimage": "Avatars.jpg",
"extract": "An avatar (Sanskrit: u0905u0935u0924u093eu0930, IAST: avatu0101ra), a concept in Hinduism that means "descent", refers to the material appearance or incarnation of a deity on earth. The relative verb to "alight, to make one's appearance" is sometimes used to refer to any guru or revered human being.nThe word avatar does not appear in the Vedic literature, but appears in verb forms in post-Vedic literature, and as a noun particularly in the Puranic literature after the 6th century CE. Despite that, the concept of an avatar is compatible with the content of the Vedic literature like the Upanishads as it is symbolic imagery of the Saguna Brahman concept in the philosophy of Hinduism. The Rigveda describes Indra as endowed with a mysterious power of assuming any form at will. The Bhagavad Gita expounds the doctrine of Avatara but with terms other than avatar.nTheologically, the term is most often associated with the Hindu god Vishnu, though the idea has been applied to other deities. Varying lists of avatars of Vishnu appear in Hindu scriptures, including the ten Dashavatara of the Garuda Purana and the twenty-two avatars in the Bhagavata Purana, though the latter adds that the incarnations of Vishnu are innumerable. The avatars of Vishnu are important in Vaishnavism theology. In the goddess-based Shaktism tradition of Hinduism, avatars of the Devi in different appearances such as Tripura Sundari, Durga and Kali are commonly found. While avatars of other deities such as Ganesha and Shiva are also mentioned in medieval Hindu texts, this is minor and occasional. The incarnation doctrine is one of the important differences between Vaishnavism and Shaivism traditions of Hinduism.nIncarnation concepts similar to avatar are also found in Buddhism, Christianity and others. The scriptures of Sikhism include the names of numerous Hindu gods and goddesses, but it rejected the doctrine of savior incarnation and endorsed the view of Hindu Bhakti movement saints such as Namdev that formless eternal god is within the human heart and man is his own savior."
}
}
}
}

。它是如此接近完美,以至于我简直不敢相信......唯一的问题是没有办法将搜索限制在"英语电影"类别。


问题:generator=categorymember不会显示页面图像,也不会按前缀过滤,只按前缀设置起点

以下是使用generator=categorymember进行搜索:

https://en.wikipedia.org/w/api.php?action=query&format=json&prop=pageimages&generator=categorymembers&piprop=name%7Cthumbnail%7Coriginal&pithumbsize=100&gcmtitle=Category%3AEnglish-language%20films&gcmprop=&gcmtype=page&gcmlimit=10&gcmstartsortkeyprefix=Avatar

这是前十个结果(我已关闭prop=extractprop=info参数 - 它们工作正常 - 因此您可以看到相关细节):

{
"batchcomplete": "",
"continue": {
"gcmcontinue": "page|2953314335314b4d04354b394141011201dcbedc08|47013432",
"continue": "gcmcontinue||"
},
"query": {
"pages": {
"4273140": {
"pageid": 4273140,
"ns": 0,
"title": "Avatar (2009 film)"
},
"15945267": {
"pageid": 15945267,
"ns": 0,
"title": "Avatar (2004 film)"
},
"25813358": {
"pageid": 25813358,
"ns": 0,
"title": "Avatar 2"
},
"27442998": {
"pageid": 27442998,
"ns": 0,
"title": "Avatar 3"
},
"50071841": {
"pageid": 50071841,
"ns": 0,
"title": "Ave Maria (1918 film)"
},
"41748079": {
"pageid": 41748079,
"ns": 0,
"title": "Avenged (2013 U.S. film)"
},
"42739169": {
"pageid": 42739169,
"ns": 0,
"title": "Avenger (film)"
},
"50726142": {
"pageid": 50726142,
"ns": 0,
"title": "The Avenger (1931 film)"
},
"43707905": {
"pageid": 43707905,
"ns": 0,
"title": "The Avengers (1950 film)"
},
"22114132": {
"pageid": 22114132,
"ns": 0,
"title": "The Avengers (2012 film)"
}
}
}
}

如您所见:

  1. pageimages数据无处可见
  2. 设置gcmstartsortkeyprefix=Avatar仅设置列表的起始点,实际上不会筛选出没有该前缀的结果。没有类似gapprefix参数,使用generator-allpages时可用。

问题:list=search不会显示任何prop值,也不会按内容和标题进行搜索

这是使用list=search进行搜索,我感谢此页面的方法:

https://en.wikipedia.org/w/api.php?action=query&format=jsonfm&prop=info%7Cpageimages%7Cextracts&list=search&inprop=url%7Cdisplaytitle&piprop=name%7Cthumbnail%7Coriginal&pithumbsize=100&exintro=1&explaintext=1&srsearch=Avatar+incategory:English-language_films&srlimit=3

这是返回(仅前 3 个结果):

{
"batchcomplete": "",
"continue": {
"sroffset": 3,
"continue": "-||info|pageimages|extracts"
},
"query": {
"searchinfo": {
"totalhits": 224
},
"search": [
{
"ns": 0,
"title": "Avatar (2009 film)",
"pageid": 4273140,
"size": 201954,
"wordcount": 18643,
"snippet": "<span class="searchmatch">Avatar</span>, marketed as James Cameron's <span class="searchmatch">Avatar</span>, is a 2009 American epic science fiction film directed, written, produced, and co-edited by James Cameron, and",
"timestamp": "2018-05-01T01:52:00Z"
},
{
"ns": 0,
"title": "Avatar 2",
"pageid": 25813358,
"size": 55754,
"wordcount": 5380,
"snippet": "<span class="searchmatch">Avatar</span> 2 is an upcoming American epic science fiction film directed, produced, and co-written by James Cameron, and the first of four planned sequels to",
"timestamp": "2018-05-02T10:02:34Z"
},
{
"ns": 0,
"title": "Avatar 3",
"pageid": 27442998,
"size": 17747,
"wordcount": 1374,
"snippet": "<span class="searchmatch">Avatar</span> 3 is an upcoming 2021 American epic science fiction film directed, produced, co-written, and co-edited by James Cameron, scheduled to be released",
"timestamp": "2018-05-02T10:02:45Z"
}
]
}
}

现在,这种搜索确实定义了prop=infoprop=imagesprop=extracts,但它们无处可见。此外,这种方法也没有类似gapprefix


问题:generator=search不会按内容和标题显示pageimages和搜索

这是与上面相同的搜索,但使用generator=search

https://en.wikipedia.org/w/api.php?action=query&format=jsonfm&prop=info%7Cpageimages%7Cextracts&generator=search&inprop=url%7Cdisplaytitle&piprop=name%7Cthumbnail%7Coriginal&pithumbsize=100&exintro=1&explaintext=1&gsrsearch=Avatar+incategory:English-language_films&gsrlimit=3

结果如下:

{
"batchcomplete": "",
"continue": {
"gsroffset": 3,
"continue": "gsroffset||"
},
"query": {
"pages": {
"4273140": {
"pageid": 4273140,
"ns": 0,
"title": "Avatar (2009 film)",
"index": 1,
"contentmodel": "wikitext",
"pagelanguage": "en",
"pagelanguagehtmlcode": "en",
"pagelanguagedir": "ltr",
"touched": "2018-05-01T01:52:00Z",
"lastrevid": 839068297,
"length": 201954,
"fullurl": "https://en.wikipedia.org/wiki/Avatar_(2009_film)",
"editurl": "https://en.wikipedia.org/w/index.php?title=Avatar_(2009_film)&action=edit",
"canonicalurl": "https://en.wikipedia.org/wiki/Avatar_(2009_film)",
"displaytitle": "<i>Avatar</i> (2009 film)",
"extract": "Avatar, marketed as James Cameron's Avatar, is a 2009 American epic science fiction film directed, written, produced, and co-edited by James Cameron, and starring Sam Worthington, Zoe Saldana, Stephen Lang, Michelle Rodriguez, and Sigourney Weaver. The film is set in the mid-22nd century, when humans are colonizing Pandora, a lush habitable moon of a gas giant in the Alpha Centauri star system, in order to mine the mineral unobtanium, a room-temperature superconductor. The expansion of the mining colony threatens the continued existence of a local tribe of Na'vi u2013 a humanoid species indigenous to Pandora. The film's title refers to a genetically engineered Na'vi body with the mind of a remotely located human that is used to interact with the natives of Pandora.nDevelopment of Avatar began in 1994, when Cameron wrote an 80-page treatment for the film. Filming was supposed to take place after the completion of Cameron's 1997 film Titanic, for a planned release in 1999, but, according to Cameron, the necessary technology was not yet available to achieve his vision of the film. Work on the language of the film's extraterrestrial beings began in 2005, and Cameron began developing the screenplay and fictional universe in early 2006. Avatar was officially budgeted at $237 million. Other estimates put the cost between $280 million and $310 million for production and at $150 million for promotion. The film made extensive use of new motion capture filming techniques, and was released for traditional viewing, 3D viewing (using the RealD 3D, Dolby 3D, XpanD 3D, and IMAX 3D formats), and for "4D" experiences in select South Korean theaters. The stereoscopic filmmaking was touted as a breakthrough in cinematic technology.nAvatar premiered in London on December 10, 2009, and was internationally released on December 16 and in the United States and Canada on December 18, to positive critical reviews, with critics highly praising its groundbreaking visual effects. During its theatrical run, the film broke several box office records and became the highest-grossing film of all time, as well as in the United States and Canada, surpassing Cameron's Titanic, which had held those records for twelve years. It also became the first film to gross more than $2 billion and the best-selling film of 2010 in the United States. Avatar was nominated for nine Academy Awards, including Best Picture and Best Director, and won three, for Best Art Direction, Best Cinematography and Best Visual Effects. Following the film's success, Cameron signed with 20th Century Fox to produce four sequels: Avatar 2 and Avatar 3 are currently filming, and will be released on December 18, 2020, and December 17, 2021 respectively; subsequent sequels will start shooting as soon as they wrap filming, and will be released in 2024 and 2025. Several cast members are expected to return, including Worthington, Saldana, Lang, and Weaver."
},
"25813358": {
"pageid": 25813358,
"ns": 0,
"title": "Avatar 2",
"index": 2,
"contentmodel": "wikitext",
"pagelanguage": "en",
"pagelanguagehtmlcode": "en",
"pagelanguagedir": "ltr",
"touched": "2018-05-02T10:02:34Z",
"lastrevid": 839266311,
"length": 55754,
"fullurl": "https://en.wikipedia.org/wiki/Avatar_2",
"editurl": "https://en.wikipedia.org/w/index.php?title=Avatar_2&action=edit",
"canonicalurl": "https://en.wikipedia.org/wiki/Avatar_2",
"displaytitle": "<i>Avatar 2</i>",
"extract": "Avatar 2 is an upcoming American epic science fiction film directed, produced, and co-written by James Cameron, and the first of four planned sequels to his film Avatar (2009). Cameron is producing the film with Jon Landau, with Josh Friedman originally announced as his co-writer; it was later announced that Cameron, Friedman, Rick Jaffa, Amanda Silver, and Shane Salerno took a part in the writing process of all sequels before being attributed separate scripts, making the eventual writing credits unclear. Cast members Sam Worthington, Zoe Saldana, Stephen Lang, Sigourney Weaver, Giovanni Ribisi, Joel David Moore, Dileep Rao, C. C. H. Pounder, and Matt Gerald are all expected to return.nCameron, who had stated in 2006 that he would like to make sequels to Avatar if it were successful, announced the first two in 2010 following the widespread success of the first film, with Avatar 2 aiming for a 2014 release. However, the subsequent addition of two more sequels, and the necessity to develop new technology in order to film performance capture scenes underwater, a feature never accomplished before in motion capture history, led to significant delays to allow the crew more time to work on the writing, pre-production, and visual effects; it is currently planned for a release on December 18, 2020, exactly eleven years after the American release of the first film, with the following sequels to be released between 2021 and 2025.nPreliminary shooting for the film started in Manhattan Beach, California on August 15, 2017, followed by principal photography simultaneously with Avatar 3 in New Zealand on September 25, 2017. The other sequels are expected to start shooting as soon as Avatar 2 and 3's filming wraps."
},
"27442998": {
"pageid": 27442998,
"ns": 0,
"title": "Avatar 3",
"index": 3,
"contentmodel": "wikitext",
"pagelanguage": "en",
"pagelanguagehtmlcode": "en",
"pagelanguagedir": "ltr",
"touched": "2018-05-02T10:02:45Z",
"lastrevid": 839266333,
"length": 17747,
"fullurl": "https://en.wikipedia.org/wiki/Avatar_3",
"editurl": "https://en.wikipedia.org/w/index.php?title=Avatar_3&action=edit",
"canonicalurl": "https://en.wikipedia.org/wiki/Avatar_3",
"displaytitle": "<i>Avatar 3</i>",
"extract": "Avatar 3 is an upcoming 2021 American epic science fiction film directed, produced, co-written, and co-edited by James Cameron, scheduled to be released on December 17, 2021. It is the second of four planned sequels to his film Avatar (2009), and will be a follow-up to Avatar 2 (2020). Cameron is producing the film with Jon Landau, with Rick Jaffa and Amanda Silver originally announced as his co-writers; it was later announced that Cameron, Jaffa, Silver, Josh Friedman and Shane Salerno took a part in the writing process of all of the sequels before being assigned to finish the separate scripts, making the eventual writing credits unclear. Cast members Sam Worthington, Zoe Saldana, Stephen Lang, Sigourney Weaver, Joel David Moore, CCH Pounder and Matt Gerald are all expected to return from the first two films.nAvatar 3 started shooting simultaneously with Avatar 2 on August 15, 2017. Two additional sequels will start shooting as soon as the first two wrap post-production, and are expected to be released in 2024 and 2025 respectively."
}
}
}
}

。再一次,这个非常接近完美,因为在这个版本中它确实返回了prop=infoprop=extracts结果,但它再次忽略了prop=pageimages,我找不到任何方法将搜索限制为标题的开头字母。


结论:SNAFU

。这里有没有"一次搜索来统治他们所有人"?这太诱人了,我几乎可以通过一个查询获得所有内容,但最终我不知道如何获取所有内容。谁能帮我穿过灌木丛?

在高层次上,列表模块生成一些页面列表(例如,最近编辑的页面)。有时它们包含一些附加信息,但大多数情况下它们只是为了给您一个页面列表。道具模块在页面列表上运行,并为每个页面添加某种额外信息;列表可以由客户端(通过titlespageids等参数)或列表模块(用作generator=而不是list=)确定。您可以使用list=prop="在一起",但所做的只是创建两个单独的列表(其中一个将为空且不显示,因为没有titlesgenerator参数)。

你的生成器查询很好;如果你想在输出中使用非自由图像,你需要pilicense=any。也许您发现了一些没有提及的过时文档?

您可以在标题搜索的搜索词中使用intitle:...(请参阅文档)。

最新更新