带有Python的Wikipedia API JSON

ian*_*ell 2 python api json wikipedia

我想从Wikipedia API调用的JSON文件中列出所有Vincent van Gogh绘画的Python列表。这是我用来发出请求的网址:

http://en.wikipedia.org/w/api.php?format=json&action=query&titles=list%20of%20works%20by%20Vincent%20van%20Gogh&Page&prop=revisions&rvprop=content

如您所见,如果您在浏览器中打开URL,那是一大堆文本。如何开始从大量的JSON返回中提取绘画的标题?在问这个问题之前,我已经做了大量研究,并尝试了许多方法来解决它。如果此JSON文件是可以使用的有用字典,那将很有帮助,但我无法理解。您如何从该JSON文件中提取绘画名称?

ale*_*cxe 5

与其直接解析JSON API调用的结果,不如使用python包装器

import wikipedia

page = wikipedia.page("List_of_works_by_Vincent_van_Gogh")
print page.links
Run Code Online (Sandbox Code Playgroud)

还有其他客户和包装器

另外,这是使用BeautifulSoupHTML解析器的选项:

>>> from bs4 import BeautifulSoup
>>> url = "http://en.wikipedia.org/wiki/List_of_works_by_Vincent_van_Gogh"
>>> soup = BeautifulSoup(urlopen(url))
>>> table = soup.find('table', class_="wikitable")
>>> for row in table.find_all('tr')[1:]:
...     print(row.find_all('td')[1].text)
... 
Still Life with Cabbage and Clogs
Crouching Boy with Sickle, Black chalk and watercolor
Woman Sewing, Watercolor
Woman with White Shawl
...
Run Code Online (Sandbox Code Playgroud)