Skip to content

Instantly share code, notes, and snippets.

@salgo60
Forked from VladimirAlexiev/README.md
Last active March 20, 2021 11:37
Show Gist options
  • Save salgo60/0550a4978b0bbe0a1cc82f4544869f02 to your computer and use it in GitHub Desktop.
Save salgo60/0550a4978b0bbe0a1cc82f4544869f02 to your computer and use it in GitHub Desktop.
Google Sheets to Wikidata

How to use Google Sheets to Get Wikidata Qnumber based on the Swedish Organization number

=CONCATENATE("https://query.wikidata.org/sparql?query=SELECT*{?item wdt:P6460%20%22",D3,"%22}") 
  • create the webcrawl
=SUBSTITUTE(IMPORTXML(C3,"//*[name()='uri']"),"http://www.wikidata.org/entity/","")
  • The data returned is the below and the part //*[name()='uri' is a XPath that fetches the WD ID from the resulting XML.
<?xml version='1.0' encoding='UTF-8'?>
<sparql xmlns='http://www.w3.org/2005/sparql-results#'>
	<head>
		<variable name='item'/>
	</head>
	<results>
		<result>
			<binding name='item'>
				<uri>http://www.wikidata.org/entity/Q3372219</uri>
			</binding>
		</result>
	</results>
</sparql>
  • Making more API calls is slow, so Google sheet initially shows "Loading…" for all rows, and gradually "materializes" the WD IDs (Qnnnn) as they come in.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment