Pywikibot/MediaWiki网站的类模块

site.newpages 编辑

...
gen = site.newpages( namespaces = 0,returndict = True,patrolled= False) 
    for page in gen:
        print(page) 
        print(type(page)) # type函数有返回对象类型的功能 
        print(page[0].title(as_url=True))
...

title() 编辑

  • 其中存在as_url参数,当为True时,以16进制Ascii码形式输出url。->more

参数 编辑

  • 其中产生的对象取决于参数 returndict。
(Page('內維爾·韓德森'), {'type': 'new', 'ns': 0, 'title': '內維爾·韓德森', 'pageid': 7070370, 'revid': 59946154, 'old_revid': 0, 'rcid': 122322655, 'user': 'Aronlee90', 'new': '', 'oldlen': 0, 'newlen': 742, 'timestamp': '2020-06-04T01:37:58Z', 'comment': '[[User:逆襲的天邪鬼/js/link-ts.js|翻译]]外文链接', 'tags': []})
  • 如果为 False,将输出一个元组,默认由一个Page对象,时间戳(unicode),长度(int),空的unicode字符串,用户名或IP地址(str),注释(unicode)组成。
(Page('內維爾·韓德森'), '2020-06-04T01:37:58Z', 742, '', 'Aronlee90', '[[User:逆襲的天邪鬼/js/link-ts.js|翻译]]外文链接')
  • 其中 namespaces 参数将选择输出对应的名字空间的页面。
    • namespaces = 0 将输出中文维基百科最近更改中的新条目,也就是 namespaces 空间为 0 的页面。
  • 其中 patrolled 参数为 True 则为巡查过的页面, False 为未经巡查的页面。(对于没有patroller权限的账户会无法使用)

输出 编辑

  • 其中第三个print输出的是:
    • 其中“page[0]”产生元组中下标索引为0的值
    • “.title()”产生元组下标为0的也就是page对象的对应的页面名(str)
內維爾·韓德森

参见 编辑