我正在尝试从维基数据中提取“也被称为”的-information。例如,通过访问猫王(https://www.wikidata.org/wiki/Q303)的页面,我想访问“猫王,猫王,摇滚乐之王”的信息。
我使用pywikibot作为Python3.5的脚本。
我知道我可以抓取页面的文本(似乎不包含这些同义词),以及在右侧有翻译的Itempage。
import pywikibot
site = pywikibot.Site('en', 'wikipedia')
page = pywikibot.Page(site, 'Elvis Presley')
item = pywikibot.ItemPage.fromPage(page)
item.get() # you need to call it to access any data.
sitelinks = item.sitelinks
print(sitelinks)提前谢谢你!
发布于 2021-02-03 22:54:15
你的代码看起来不错。您只需获取别名,而不是站点链接,例如:
from pprint import pprint
pprint(item.aliases['en'])这将为您提供预期的列表:
['Elvis',
'Elvis Aaron Presley',
"The King of Rock'n'Roll",
"King of Rock'n'Roll",
'Elvis Aron Presley',
"The King of Rock 'n' Roll",
"King of Rock 'n' Roll",
'The King',
'Elvis A. Presley']https://stackoverflow.com/questions/46121942
复制相似问题