@@ -27,7 +27,7 @@ result_count = 1
2727# urls
2828wikidata_host = 'https://www.wikidata.org'
2929url_search = wikidata_host \
30− + '/wiki/Special:ItemDisambiguation?{query}'
30+ + '/w/index.php?{query}'
3131
3232wikidata_api = wikidata_host + '/w/api.php'
3333url_detail = wikidata_api\
@@ -40,7 +40,7 @@ url_map = 'https://www.openstreetmap.org/'\
4040url_image = 'https://commons.wikimedia.org/wiki/Special:FilePath/{filename}?width=500&height=400'
4141
4242# xpaths
43−wikidata_ids_xpath = '//div/ul[@class="wikibase-disambiguation"]/li/a/@title'
43+wikidata_ids_xpath = '//ul[@class="mw-search-results"]/li//a/@href'
4444title_xpath = '//*[contains(@class,"wikibase-title-label")]'
4545description_xpath = '//div[contains(@class,"wikibase-entitytermsview-heading-description")]'
4646property_xpath = '//div[@id="{propertyid}"]'
@@ -57,22 +57,21 @@ calendar_name_xpath = './/sup[contains(@class,"wb-calendar-name")]'
5757
5858
5959def request(query, params):
60− language = match_language(params['language'], supported_languages).split('-')[0]
61−
6260 params['url'] = url_search.format(
63− query=urlencode({'label': query, 'language': language}))
61+ query=urlencode({'search': query}))
6462 return params
6563
6664
6765def response(resp):
6866 results = []
6967 html = fromstring(resp.text)
70− wikidata_ids = html.xpath(wikidata_ids_xpath)
68+ search_results = html.xpath(wikidata_ids_xpath)
7169
7270 language = match_language(resp.search_params['language'], supported_languages).split('-')[0]
7371
7472 # TODO: make requests asynchronous to avoid timeout when result_count > 1
75− for wikidata_id in wikidata_ids[:result_count]:
73+ for search_result in search_results[:result_count]:
74+ wikidata_id = search_result.split('/')[-1]
7675 url = url_detail.format(query=urlencode({'page': wikidata_id, 'uselang': language}))
7776 htmlresponse = get(url)
7877 jsonresponse = loads(htmlresponse.text)