WikipediaAPI python返回奇怪的结果

2024-05-23 20:52:07 发布

您现在位置:Python中文网/ 问答频道 /正文

import wikipedia

print(wikipedia.summary("Tomato", sentences=3))

为什么这段代码返回一个带有“tom tom”的消歧错误,而不仅仅是条目“tomato”的求和/消歧错误? 搜索词显然不是tom tom或者我在这里遗漏了什么?为什么这不起作用


Tags: 代码import错误sentences条目summarywikipediaprint
1条回答
网友
1楼 · 发布于 2024-05-23 20:52:07

搜索"Tomato"会得到建议"tom tom"。不知道为什么。。。在任何情况下,您都可以在wikipedia.summary中禁用auto_suggest

import wikipedia

wikipedia.summary("Tomato", sentences=3, auto_suggest=False)

输出是

'The tomato is the edible, often red, berry of the plant Solanum lycopersicum, commonly known as a tomato plant.  The species originated in western South America and Central America. The Nahuatl (the language used by the Aztecs) word tomatl gave rise to the Spanish word tomate, from which the English word tomato derived.'

您可以看到,使用wikipedia.search函数搜索"Tomato"表明"tom tom"

results, suggestion = wikipedia.search("Tomato", suggestion=True)

{}是{},而{}是与番茄密切相关的标题列表

相关问题 更多 >