Skip to content

Instantly share code, notes, and snippets.

@putnik
Created May 25, 2019 13:35
Show Gist options
  • Save putnik/172d857c75e59d582ce3ef60d1d8f6ca to your computer and use it in GitHub Desktop.
Save putnik/172d857c75e59d582ce3ef60d1d8f6ca to your computer and use it in GitHub Desktop.
<html>
<head>
<script src="http://code.jquery.com/jquery-2.0.0.js"></script>
<script>
var sparql = `
select ?item ?itemLabel ?article {
?item wdt:P31/wdt:P279/wdt:P279 wd:Q174211 .
?item wdt:P279 wd:Q11173
OPTIONAL { ?article schema:about ?item; schema:isPartOf <https://ru.wikipedia.org/> }
SERVICE wikibase:label { bd:serviceParam wikibase:language "ru,en" }
}`;
fetch('https://query.wikidata.org/sparql?format=json&query=' + encodeURIComponent(sparql), {
headers: {
"Accept":"application/sparql-results+json",
},
})
.then(function(response) {
return response.json();
})
.then(function(json) {
var $list = $('#list');
for (var i in json.results.bindings) {
var item = json.results.bindings[i];
console.log(item);
$list.append('<li>' + item.itemLabel.value + '</li>');
};
console.log();
})
.catch( alert );
</script>
</head>
<body>
<ul id="list"></ul>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment