Jump to content

Pywikipediabot/Pywikipediabot basics/Getting one page: Difference between revisions

From IdeaWazaWiki
wikademia>Millosh
New page: Software should know with which site you are trying to operate. Usually, it is your default language and family inside of your user-config.py file: <source lang="python"> mylang = 'en' fa...
 
wikademia>Eme
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Software should know with which site you are trying to operate. Usually, it is your default language and family inside of your user-config.py file:
The software should know on which site you are trying to operate. Usually, this is your default language and family inside of your user-config.py file:


<source lang="python">
<source lang="python">
Line 6: Line 6:
</source>
</source>


By defining object "site" (or whatever name you give to this object) bot will start to use this site:
By defining object "site" (or whatever name you give to this object) the bot will start to use this site:


<source lang="python">
<source lang="python">
Line 12: Line 12:
</source>
</source>


While it is usual that you are working with only one site, it will be better to always define used language and family:
Even when it is usual that you are working with only one site, it will be better to always define the used language and family:


<source lang="python">
<source lang="python">
Line 20: Line 20:
</source>
</source>


Now, we have defined object "site" and we are ready to get our first page. To do so, we have to define object "page" (or whatever name you give to this object). Let's say that we want to get source of Main Page:
Now, we have defined object "site" and we are ready to fetch our first page. To do so, we have to define object "page" (or whatever name you give to this object). Let's say that we want to get the source of Main Page:


<source lang="python">
<source lang="python">

Latest revision as of 17:07, 8 November 2009

The software should know on which site you are trying to operate. Usually, this is your default language and family inside of your user-config.py file:

<source lang="python"> mylang = 'en' family = 'wikinews' </source>

By defining object "site" (or whatever name you give to this object) the bot will start to use this site:

<source lang="python"> site = getSite() </source>

Even when it is usual that you are working with only one site, it will be better to always define the used language and family:

<source lang="python"> language = "en" family = "wikinews" site = getSite(language,family) </source>

Now, we have defined object "site" and we are ready to fetch our first page. To do so, we have to define object "page" (or whatever name you give to this object). Let's say that we want to get the source of Main Page:

<source lang="python"> pagename = "Main Page" page = Page(site,pagename) pagetext = page.get() </source>

And if you invoke "print pagetext", you will get Main Page of English Wikinews:

{{Main page header}}
{{Ticker}}

{|{|cellpadding="5" cellspacing="3" class="mainpagetable"
|- 
| style="border: 1px solid #FFFFFF; padding: .5em 1em 1em; color: #000000; background-color: #ffffff; width:60%; vertical-align: top;" rowspan="3" |
{{Lead article}}
----
<div class="MainPageLatestNews">
=== Latest news <span class="plainlinks" style="font-size:70%;text-align:right;">[http://feeds.feedburner.com/WikinewsLatestNews <span class="rss">RSS</span>]</span>===
{{Latest news}}</div>
...