All Free <Script>

tips and tricks per webmaster

Estrapolare informazioni da wikipedia

12 Luglio 2016        

Grazie alle api di wikipedia รจ possibile estrapolare i suoi contenuti nel formato json. Di seguito un esempio:

<html>
	<head>
		<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
		<script type="text/javascript">

		    $(document).ready(function () {
			
			var trova = "spaghetti";

			$.getJSON("https://it.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro=&explaintext=&callback=?&titles=" + trova, function (data) {
			    $.each(data.query.pages, function (i, item) {
				$("#contenuto").html(item.extract);
			    });
			});
		    });
		</script>
	</head>
<body>
	<div id="contenuto"></div>
</body>
</html>