Jump to content
MediaWiki

Manual:Pywikibot/Create your own script/bg

From mediawiki.org
This page is a translated version of the page Manual:Pywikibot/Create your own script and the translation is 13% complete.
Pywikibot logo
Pywikibot
  • Configuration and scripts
  • Uses
Още... »
v · d · e

Тази страница съдържа някои основни съвети как да започнете да пишете свой собствен бот. Уверете се, че сте настроили вашия user-config.py файл!

You can either use the following commands in a shell, or in a script.

To open a shell, run python pwb.py shell.

As a script, please save the file as myscript.py in the scripts/userscripts/ directory, then run python pwb.py myscript.

  • To gain access to the pywikibot library from your Python script, use:
importpywikibot
  • to retrieve a page, use the following, where pageName is the title of the page you would like to retrieve (e.g., Wikipedia:Bots or India):
site = pywikibot.Site()
page = pywikibot.Page(site, "pageName")
text = page.text
  • to update a page, use:
page.text = "newText"
page.save("Edit comment")
  • look at some of the pywikibot files for other ideas -- scripts/basic.py is relatively easy to read even if you're new to pywikibot.
  • basic.py gives you a setup that can be used for many different bots, all you have to do is define the string editing on the page text.
importpywikibot
frompywikibotimport pagegenerators
site = pywikibot.Site()
cat = pywikibot.Category(site,'Category:Living people')
gen = pagegenerators.CategorizedPageGenerator(cat)
for page in gen:
 #Do something with the page object, for example:
 text = page.text

Вижте също


If you need more help on setting up your Pywikibot visit the #pywikibot IRC channel connect or pywikibot@ mailing list.

AltStyle によって変換されたページ (->オリジナル) /