-6ren">
gpt4 book ai didi

python-3.x - 维基百科Python API

转载 作者:行者123 更新时间:2023-12-02 23:01:26 27 4
gpt4 key购买 nike

我正在尝试使用Python的维基百科API查看维基百科页面中的目录。这是我的代码。

>>> import wikipedia
>>> ny = wikipedia.page("New York")
>>> ny.sections

但结果是我得到一个空列表[]。当我进入该页面并检查时,我可以看到目录中有内容。除了这一点之外,文档中所说的所有其他内容似乎都有效。我是来自 java 背景的 python 新手。

最佳答案

当前版本的 Wikipedia API python 库存在错误。您可以通过 lucasdnd on 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']

希望是 fixed in the main library很快的某个时候。

关于python-3.x - 维基百科Python API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34869597/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com