import pywikibot
site = pywikibot.Site("wikidata", "wikidata")
site
DataSite("wikidata", "wikidata")
page = pywikibot.Page(site, "Tatooine")
page
Page('Tatooine')
page.exists()
False
page.text
''
for page in site.search("Tatooine"):
    print(page)
---------------------------------------------------------------------------
Error                                     Traceback (most recent call last)
<ipython-input-34-4c0fe203d747> in <module>()
----> 1 for page in site.search("Tatooine", where='label'):
      2     print(page)

/srv/paws/pwb/pywikibot/tools/__init__.py in wrapper(*__args, **__kw)
   1519                              cls, depth)
   1520                     del __kw[old_arg]
-> 1521             return obj(*__args, **__kw)
   1522 
   1523         if not __debug__:

/srv/paws/pwb/pywikibot/site.py in search(self, searchstring, namespaces, where, get_redirects, total, content)
   4744             raise Error("search: searchstring cannot be empty")
   4745         if where not in where_types:
-> 4746             raise Error("search: unrecognized 'where' value: %s" % where)
   4747         if where in ('title', 'titles'):
   4748             if isinstance(self.family, WikimediaFamily):

Error: search: unrecognized 'where' value: label
from pywikibot.data import api

def getItems(site, itemtitle):
     params = { 'action' :'wbsearchentities' , 'format' : 'json' , 'language' : 'en', 'type' : 'item', 'search': itemtitle}
     request = api.Request(site=site,**params)
     return request.submit()
wikidataEntries = getItems(site, "Tatooine")
wikidataEntries
WARNING: /srv/paws/lib/python3.6/site-packages/ipykernel_launcher.py:5: DeprecationWarning: Instead of using kwargs from Request.__init__, parameters for the request to the API should be added via the "parameters" parameter.
  """

{'search': [{'concepturi': 'http://www.wikidata.org/entity/Q723764',
   'description': 'fictional planet in Star Wars',
   'id': 'Q723764',
   'label': 'Tatooine',
   'match': {'language': 'en', 'text': 'Tatooine', 'type': 'label'},
   'pageid': 680453,
   'repository': '',
   'title': 'Q723764',
   'url': '//www.wikidata.org/wiki/Q723764'},
  {'concepturi': 'http://www.wikidata.org/entity/Q7688217',
   'description': 'Star Wars novel by Troy Denning',
   'id': 'Q7688217',
   'label': 'Tatooine Ghost',
   'match': {'language': 'en', 'text': 'Tatooine Ghost', 'type': 'label'},
   'pageid': 7613783,
   'repository': '',
   'title': 'Q7688217',
   'url': '//www.wikidata.org/wiki/Q7688217'},
  {'concepturi': 'http://www.wikidata.org/entity/Q9082040',
   'description': 'Wikimedia disambiguation page',
   'id': 'Q9082040',
   'label': 'Tatooine',
   'match': {'language': 'en', 'text': 'Tatooine', 'type': 'label'},
   'pageid': 9158014,
   'repository': '',
   'title': 'Q9082040',
   'url': '//www.wikidata.org/wiki/Q9082040'},
  {'aliases': ['Tatooine'],
   'concepturi': 'http://www.wikidata.org/entity/Q1145339',
   'description': 'extrasolar planet',
   'id': 'Q1145339',
   'label': 'HD 188753 Ab',
   'match': {'language': 'es', 'text': 'Tatooine', 'type': 'label'},
   'pageid': 1091936,
   'repository': '',
   'title': 'Q1145339',
   'url': '//www.wikidata.org/wiki/Q1145339'}],
 'searchinfo': {'search': 'Tatooine'},
 'success': 1}
import pprint
repo = site.data_repository()
concepts = site.search_entities("Tatooine", "en", limit=1)
concept = next(iter(concepts))
item = pywikibot.ItemPage(repo, concept["id"])
item.get()
len(item.sitelinks)
#for concept in concepts:
#    print(concept)
#    item = pywikibot.ItemPage(repo, concept["id"])
#    item.get()
34