SE::Wikipedia::Article - scraper di articoli Wikipedia
Panoramica dello scraper
Scraper di articoli Wikipedia. In input viene fornito un link all'articolo (o il formato breve lang:title), in output si ottiene il testo completo dell'articolo in plain text, una breve descrizione, il link canonico, la thumbnail e l'immagine originale, le categorie, le versioni linguistiche, il Wikidata ID e i metadati della revisione.
I dati vengono ottenuti tramite l'ufficiale MediaWiki Action API (prop=extracts|info|pageimages|...). La lingua viene determinata dall'URL o dal prefisso della query. I redirect di Wikipedia vengono gestiti automaticamente (ad esempio, USA → United States).
Per cercare articoli tramite parole chiave, utilizza lo scraper SE::Wikipedia.
Le funzionalità di A-Parser permettono di salvare le impostazioni di scraping per un uso futuro (preset), impostare programmi di scraping e molto altro. Il salvataggio dei risultati è possibile nella forma e nella struttura necessaria, grazie al potente motore di modelli integrato Template Toolkit.
Dati raccolti
I dati vengono raccolti tramite l'API https://{lang}.wikipedia.org/w/api.php.
- Titolo dell'articolo (
title) - Breve descrizione (
description) - Testo completo dell'articolo in plain text (
text) - Link canonico (
link) - Anteprima dell'immagine (
thumb) - Immagine originale (
image) - Page ID (
pageid) - Dimensione dell'articolo in byte (
size) - Lingua dell'edizione (
lang) - Wikidata ID (
wikidata) - Orario dell'ultima revisione (
timestamp) - ID della revisione (
revid) - Elenco delle categorie (
categories) - Versioni linguistiche dell'articolo (
langlinks: lang, title, link) - JSON grezzo della risposta API (
data)
Funzionalità
- Analisi di link Wikipedia desktop, mobile e
index.php - Formato breve della query
lang:title - Segue automaticamente i redirect
- Testo completo dell'articolo in plain text (senza HTML/Markdown)
- Categorie e link linguistici con limite API
max(fino a 500) - Supporto per proxy e impostazioni generali di A-Parser
Casi d'uso
- Estrazione di testi di articoli per NLP, RAG e basi di conoscenza
- Raccolta di descrizioni e immagini per schede e bot
- Ottenimento di categorie e versioni linguistiche della pagina
- Arricchimento dei risultati di SE::Wikipedia con il testo completo dell'articolo
Query
Formati di query supportati:
- Link standard:
https://en.wikipedia.org/wiki/Albert_Einstein
https://ru.wikipedia.org/wiki/Efremov,_Ivan_Antonovich
- Link mobile:
https://en.m.wikipedia.org/wiki/Albert_Einstein
- Link di tipo
index.php:
https://en.wikipedia.org/w/index.php?title=Albert_Einstein
- Con ancora di sezione (
#...viene ignorato):
https://en.wikipedia.org/wiki/Albert_Einstein#Scientific_career
- Formato breve
lang:title:
en:Albert Einstein
ru:Efremov, Ivan Antonovich
eo:Esperanto
Vengono inoltre gestiti correttamente l'URL-encoding, gli _ nel titolo, i redirect e i codici lingua con trattino (be-tarask).
Esempi di output dei risultati
A-Parser supporta una formattazione flessibile dei risultati grazie al motore di modelli integrato Template Toolkit, che gli consente di restituire i risultati in forma libera o strutturata, come CSV o JSON.
Output predefinito
Formato del risultato:
$link\n$title\n$description\n$text\n
Esempio di risultato:
https://en.wikipedia.org/wiki/Albert_Einstein
Albert Einstein
German-born theoretical physicist (1879–1955)
Albert Einstein (14 March 1879 – 18 April 1955) was a German-born theoretical physicist best known for developing the theory of relativity. Einstein also made important contributions to quantum theory. His mass–energy equivalence formula E = mc2, which arises from special relativity, has been called "the world's most famous equation". He received the 1921 Nobel Prize in Physics for "his services to theoretical physics, and especially for his discovery of the law of the photoelectric effect".
Born as a subject to the Kingdom of Württemberg, part of the German Empire, Einstein moved to Switzerland in 1895, forsaking his citizenship the following year. In 1896, at the age of seventeen, he enrolled in the mathematics and physics teaching diploma program at the Swiss federal polytechnic school in Zurich, graduating in 1900. He acquired Swiss citizenship a year later, which he kept for the rest of his life, and afterwards secured a permanent position at the Swiss Patent Office in Bern. In 1905, he submitted a successful PhD dissertation to the University of Zurich. In 1914, he moved to Berlin to join the Prussian Academy of Sciences and the Humboldt University of Berlin, becoming director of the Kaiser Wilhelm Institute for Physics in 1917; he also became a Prussian and consequently also German citizen again. In 1933, while Einstein was visiting the United States, Adolf Hitler came to power in Germany. Horrified by the Nazi persecution of his fellow Jews, he decided to remain in the US, and was granted American citizenship in 1940. On the eve of World War II, he endorsed a letter to President Franklin D. Roosevelt alerting him to the potential German nuclear weapons program and recommending that the US begin similar research, later carried out as the Manhattan Project.
...
Titolo + descrizione + link
Formato del risultato:
$title\t$description\t$link\n
Esempio di risultato:
Albert Einstein German-born theoretical physicist (1879–1955) https://en.wikipedia.org/wiki/Albert_Einstein
Output in CSV
Formato del risultato:
[% tools.CSVline(title, description, link, pageid, wikidata, lang, size) %]
Testo iniziale:
Titolo,Descrizione,Link,Page ID,Wikidata,Lingua,Dimensione
Esempio di risultato:
"Albert Einstein","German-born theoretical physicist (1879–1955)",https://en.wikipedia.org/wiki/Albert_Einstein,736,Q937,en,238698
Categorie
Formato del risultato:
$categories.format('$name\n')
Esempio di risultato:
1879 births
1955 deaths
19th-century American Jews
19th-century German Jews
19th-century Swiss Jews
20th-century American engineers
20th-century American inventors
20th-century American letter writers
20th-century American male writers
20th-century American physicists
Versioni linguistiche
Formato del risultato:
$langlinks.format('$lang\t$title\t$link\n')
Esempio di risultato:
ab Einstein, Albert https://ab.wikipedia.org/wiki/%D0%95%D0%B8%D0%BD%D1%88%D1%82%D0%B5%D0%B8%D0%BD,_%D0%90%D0%BB%D0%B1%D0%B5%D1%80%D1%82
af Albert Einstein https://af.wikipedia.org/wiki/Albert_Einstein
gsw Albert Einstein https://als.wikipedia.org/wiki/Albert_Einstein
am አልበርት አይንስታይን https://am.wikipedia.org/wiki/%E1%8A%A0%E1%88%8D%E1%89%A0%E1%88%AD%E1%89%B5_%E1%8A%A0%E1%8B%AD%E1%8A%95%E1%88%B5%E1%89%B3%E1%8B%AD%E1%8A%95
de Albert Einstein https://de.wikipedia.org/wiki/Albert_Einstein
ru Einstein, Albert https://ru.wikipedia.org/wiki/%D0%AD%D0%B9%D0%BD%D1%88%D1%82%D0%B5%D0%B9%D0%BD,_%D0%90%D0%BB%D1%8C%D0%B1%D0%B5%D1%80%D1%82
Dump in JSON
Formato del risultato:
[%
obj = {};
obj.title = title;
obj.description = description;
obj.link = link;
obj.pageid = pageid;
obj.wikidata = wikidata;
obj.lang = lang;
obj.json _ "\n"
%]
Esempio di risultato:
{"wikidata":"Q937","link":"https://en.wikipedia.org/wiki/Albert_Einstein","lang":"en","pageid":"736","title":"Albert Einstein","description":"German-born theoretical physicist (1879–1955)"}
Impostazioni possibili
Lo scraper non ha opzioni uniche nell'interfaccia utente: la lingua e il titolo vengono presi dalla query. Vengono utilizzate solo le impostazioni comuni (proxy, tentativi, ecc.).