メインコンテンツへスキップ

SE::Wikipedia::Article - Wikipedia記事スクレイパー

スクレイパーの概要

Wikipedia記事スクレイパー。入力として記事へのリンク(または lang:title という短縮形式)を受け取り、出力として記事の全文(プレーンテキスト)、簡単な説明、カノニカルリンク、サムネイルとオリジナル画像、カテゴリ、言語版、Wikidata ID、およびリビジョンのメタデータを提供します。

データは公式の MediaWiki Action API (prop=extracts|info|pageimages|...) を通じて取得されます。言語はURLまたはクエリのプレフィックスから判別されます。Wikipediaのリダイレクトは自動的に処理されます(例: USAUnited States)。

キーワードで記事を検索するには、SE::Wikipedia スクレイパーを使用してください。

A-Parserの機能により、スクレイピング設定を将来の使用のために保存(プリセット)したり、スクレイピングのスケジュールを設定したりすることが可能です。内蔵の強力なテンプレートエンジン Template Toolkit により、必要な形式や構造で結果を保存できます。

収集されるデータ

データは API https://{lang}.wikipedia.org/w/api.php を通じて収集されます。

  • 記事のタイトル (title)
  • 簡単な説明 (description)
  • 記事の全文(プレーンテキスト) (text)
  • カノニカルリンク (link)
  • プレビュー画像 (thumb)
  • オリジナル画像 (image)
  • Page ID (pageid)
  • 記事のサイズ(バイト) (size)
  • 版の言語 (lang)
  • Wikidata ID (wikidata)
  • 最終リビジョン時刻 (timestamp)
  • リビジョンID (revid)
  • カテゴリリスト (categories)
  • 記事の言語版 (langlinks: lang, title, link)
  • APIレスポンスの生JSON (data)

機能

  • Wikipediaのデスクトップ版、モバイル版、および index.php リンクの解析
  • 短縮クエリ形式 lang:title への対応
  • リダイレクトへの自動追従
  • 記事の完全なプレーンテキスト(HTML/Markdownなし)
  • API制限 max(最大500)までのカテゴリと言語リンクの取得
  • プロキシおよびA-Parserの共通設定のサポート

ユースケース

  • NLP、RAG、およびナレッジベース用の記事テキストの抽出
  • カードやボット用の説明文と画像の収集
  • ページのカテゴリと言語版の取得
  • SE::Wikipedia の検索結果に記事全文を付加して強化

クエリ

サポートされているクエリ形式:

  1. 標準リンク:
https://en.wikipedia.org/wiki/Albert_Einstein
https://ru.wikipedia.org/wiki/Ефремов,_Иван_Антонович
  1. モバイルリンク:
https://en.m.wikipedia.org/wiki/Albert_Einstein
  1. index.php 形式のリンク:
https://en.wikipedia.org/w/index.php?title=Albert_Einstein
  1. セクションアンカー付き(#... は無視されます):
https://en.wikipedia.org/wiki/Albert_Einstein#Scientific_career
  1. 短縮形式 lang:title:
en:Albert Einstein
ja:イワン・アントーノヴィチ・エフレーモフ
eo:Esperanto

また、URLエンコード、タイトル内の _、リダイレクト、およびハイフンを含む言語コード(be-tarask)も正しく処理されます。

結果の出力例

A-Parserは、内蔵のテンプレートエンジン Template Toolkit により柔軟な結果のフォーマットをサポートしており、任意の形式や、CSVやJSONなどの構造化された形式で結果を出力できます。

デフォルト出力

結果のフォーマット:

$link\n$title\n$description\n$text\n

結果の例:

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.
...

結果のフォーマット:

$title\t$description\t$link\n

結果の例:

Albert Einstein German-born theoretical physicist (1879–1955)   https://en.wikipedia.org/wiki/Albert_Einstein

CSVへの出力

結果のフォーマット:

[% tools.CSVline(title, description, link, pageid, wikidata, lang, size) %]

ヘッダーテキスト:

タイトル,説明,リンク,ページID,Wikidata,言語,サイズ

結果の例:

"Albert Einstein","German-born theoretical physicist (1879–1955)",https://en.wikipedia.org/wiki/Albert_Einstein,736,Q937,en,238698

カテゴリ

結果のフォーマット:

$categories.format('$name\n')

結果の例:

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

結果のフォーマット:

$langlinks.format('$lang\t$title\t$link\n')

結果の例:

ab  アインシュタイン、アルベルト  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
ja アインシュタイン、アルベルト 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

JSONへのダンプ

結果のフォーマット:

[%
obj = {};
obj.title = title;
obj.description = description;
obj.link = link;
obj.pageid = pageid;
obj.wikidata = wikidata;
obj.lang = lang;
obj.json _ "\n"
%]

結果の例:

{"wikidata":"Q937","link":"https://en.wikipedia.org/wiki/Albert_Einstein","lang":"en","pageid":"736","title":"Albert Einstein","description":"German-born theoretical physicist (1879–1955)"}

設定可能な項目

このスクレイパーにはUI上に独自のオプションはありません。言語とタイトルはクエリから取得されます。共通設定(プロキシ、リトライなど)のみが使用されます。