import pywikibot
from pywikibot import pagegenerators as pg

query='select ?item where {?item wdt:P31 wd:Q5 . ?item wdt:P569 ?geb . ?item wdt:P570 ?str}'
site = pywikibot.Site('wikidata','wikidata')      #Geef aan naar welke site je wilt schrijven
repo = site.data_repository()                     #voor ophalen wikidata-items adhv Qxxxx


def wd_sparql_query(spq):
   generator=pg.WikidataSPARQLPageGenerator(spq,site=pywikibot.Site('wikidata','wikidata'))
   for wd in generator:
     try:
       wd.get(get_redirect=True)
       yield wd
     except:
       pass

def is_double_person(born,dead):
    pass

def wd_same_dob_dod(wd):
    dobdod_query='select ?item where {?item wdt:P31 wd:Q5 . ?item wdt:P569 "YYYY-MM-DD"^^xsd:dateTime . ?item wdt:P570 "YYYY-MM-DD"^^xsd:dateTime}'
    dob=wd.claims.get('P569')[0].getTarget()
    dod=wd.claims.get('P570')[0].getTarget()
    print(f'dob: {dob}')
    print(f'dod: {dod}')
    
wd=pywikibot.ItemPage(repo,'Q2326861')    
wd.get(get_redirect=True)
wd_same_dob_dod(wd)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-8e08a11496b7> in <module>
     27 wd=pywikibot.ItemPage(repo,'Q2326861')
     28 wd.get(get_redirect=True)
---> 29 wd_same_dob_dod(wd)

<ipython-input-2-8e08a11496b7> in wd_same_dob_dod(wd)
     20 def wd_same_dob_dod(wd):
     21     dobdod_query='select ?item where {?item wdt:P31 wd:Q5 . ?item wdt:P569 "YYYY-MM-DD"^^xsd:dateTime . ?item wdt:P570 "YYYY-MM-DD"^^xsd:dateTime}'
---> 22     dob=wd.claims['P569'].getTarget()
     23     dod=wd.claims['P570'].getTarget()
     24     print(f'dob: {dob}')

AttributeError: 'list' object has no attribute 'getTarget'