我正在尝试使用Wikipedia API for python在Wikipedia页面中查看目录。这是我的代码。
>>> import wikipedia
>>> ny = wikipedia.page("New York")
>>> ny.sections
但结果却是一个空列表[]
。当我转到页面进行检查时,可以看到目录中有内容。除此以外,文档中所说的所有其他内容似乎都起作用。我是来自Java背景的Python新手。
当前版本的Wikipedia API python库中存在一个错误。您可以通过lucasdnd在github上安装一个分支来解决此问题:
pip install git+https://github.com/lucasdnd/Wikipedia.git
(--upgrade
如果已经安装,则可以)
现在:
>>> import wikipedia
>>> ny = wikipedia.page("New York")
>>> ny.sections
[u'History', u'16th century', u'17th century', u'18th century, the American Revolution, and statehood', u'19th century', u'Immigration', u'September 11, 2001 attacks', u'Hurricane Sandy, 2012', u'Geography', u'Climate', u'Statescape', u'Regions', u'Adjacent geographic entities', u'State parks', u'National parks', u'Administrative divisions', u'Demographics', u'Population', u'Most populous counties', u'Major cities', u'Metropolitan areas', u'Racial and ancestral makeup', u'Languages', u'Religion', u'LGBT', u'Economy', u'Wall Street', u'Silicon Alley', u'Microelectronic hardware and photographic processing', u'Media and entertainment', u'Tourism', u'Exports', u'Education', u'Transportation', u'Government and politics', u'Government', u'Capital punishment', u'Federal representation', u'Politics', u'Sports', u'See also', u'References', u'Further reading', u'External links']
希望它将很快在主库中修复。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句