Wikidata:Pywikibot - Python 3 Tutorial/linked pages

Get linked pages from itemsEdit

# -*- coding: utf-8  -*-
import pywikibot
Using PyWikiBot to get all the sitelinks/entries connected to Wikipedia, and the number of entries.
site = pywikibot.Site("wikidata", "wikidata")
repo = site.data_repository()
item = pywikibot.ItemPage(repo, "Q36153")

y = 0

for x in item.sitelinks:
    if x.endswith('wiki'):
        y = y + 1
print("Number of WP sitelinks/entries: ",y)

Result: Wikipedia site and name of the article in that language.

afwiki Beyoncé Knowles
alswiki Beyoncé Knowles
amwiki ቢዮንሴ
anwiki Beyoncé
arwiki بيونسيه
arzwiki بيونساى نوويلز
astwiki Beyoncé
azbwiki بیانسه
azwiki Beyonse
barwiki Beyoncé Knowles
bclwiki Beyonce
yowiki Beyoncé Knowles
zh_min_nanwiki Beyoncé Knowles
zh_yuewiki 碧昂絲
zhwiki 碧昂絲
Number of WP sitelinks/entries:  116