Manual:Pywikibot/pagegenerators.py

This page is a translated version of the page Manual:Pywikibot/pagegenerators.py and the translation is 39% complete.

pagegenerators.py は、他のスクリプト向けにページの一覧を生成するために使用される Pywikibot スクリプトです。

This module offers a wide variety of page generators. A page generator is an object that is iterable (see https://www.python.org/dev/peps/pep-0255/) and that yields page objects which other scripts can then use.

コマンドラインの使用法

The pagegenerators.py may not be executed directly. Instead, the script listpages.py can be used.

例:

$ python pwb.py listpages -search:'foobar'

This will return, in standard output, a list of all pages containing "foobar", as returned by MediaWiki's search engine.

See listpages.py for more details.

別のスクリプトからの呼び出し

Category crawler:

from pywikibot import pagegenerators

site = pywikibot.Site()
cat = pywikibot.Category(site, 'Category name')
pages = cat.articles()
for page in pagegenerators.PreloadingGenerator(pages, 100):
    # some treatment of generated pages

Subcategories explorer:

gen = pagegenerators.CategorizedPageGenerator(cat, recurse=True)

MySQL リクエスト (Manual:Pywikibot/MySQL 参照):

gen = pagegenerators.MySQLPageGenerator(query)

Unicode recommendation

The following code returns KeyError: 'query' because of the special character:

gen = pagegenerators.SearchPageGenerator('´', namespaces = [0])

If searching in user and mediawiki namespaces, it would look like

gen = pagegenerators.SearchPageGenerator('´', namespaces = [2, 8])

Consequently, an encoding conversion is needed:

gen = pagegenerators.SearchPageGenerator("´", namespaces = [0])

関連項目