我在linux中使用PywikiBot核心版本来创建一个程序来简单地获取维基百科页面的类别。我的代码是:
# -*- coding: utf-8 -*-
import pywikibot
site = pywikibot.Site("en")
page = pywikibot.Page(site, u"Wikipedia:Sandbox")
item = pywikibot.ItemPage.fromPage(page)
dictionary = item.get()
print page.categories
我希望得到类别,但我得到:
<bound method Page.categories of Page(Wikipedia:Sandbox)>
我遵循本教程,但我应该说 pywikibot 中的文档写得不好,您应该打开文件以查找一些信息,我发现了def 类别:
def categories(self, withSortKey=False, step=None, total=None,
content=False):
"""Iterate categories that the article is in.
@param withSortKey: if True, include the sort key in each Category.
@param step: limit each API call to this number of pages
@param total: iterate no more than this number of pages in total
@param content: if True, retrieve the content of the current version
of each category description page (default False)
@return: a generator that yields Category objects.
"""
return self.site.pagecategories(self, withSortKey=withSortKey,
step=step, total=total, content=content)
而且我不喜欢更改框架代码。