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

SE::Wikipedia - Wikipedia検索スクレイパー

スクレイパーの概要

Wikipedia検索結果のスクレイパーです。公式の MediaWiki Action API を通じてキーワードで百科事典の記事を検索し、リンク、タイトル、スニペット、短い説明、画像のプレビュー、ページID、記事サイズなどの構造化された結果を取得できます。

すべての言語版のWikipedia(en, ru, de, ja, simple, be-taraskなど)をサポートしています。1ページの検索結果は最大 20 件(API extractsの制限)、ページネーションは最大 50 ページまで対応しています。ページ間の重複は自動的にフィルタリングされます。

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

記事の全文を取得するには、SE::Wikipedia::Article スクレイパーを使用してください。

収集されるデータ

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

  • 総結果数 (totalcount)
  • 記事へのリンク
  • タイトル (anchor)
  • スニペット (plain text extract)
  • 短い説明 (description)
  • 画像のプレビュー(存在する場合)
  • Page ID
  • 記事のサイズ(バイト)

機能

  • あらゆる言語版のWikipediaでの検索 (言語版リスト)
  • スニペットの長さ設定(最大 1200 文字 — MediaWiki TextExtractsの最大値)
  • 最大 50 ページ × 20 件の結果のページネーション
  • 検索結果ページ間の記事の自動重複排除
  • プロキシのサポートとA-Parserの共通設定への対応

ユースケース

  • Wikipedia記事のリンクデータベースの収集
  • コンテンツやSEOのためのキーワードに関連する記事の選定
  • チャットボットや参照システム用のスニペットと説明の取得
  • SE::Wikipedia::Article を使用した記事のさらなる解析

クエリ

クエリには、次のような検索フレーズを指定する必要があります:

Albert Einstein
Ivan Yefremov
Berlin
東京
Kyiv

検索言語はクエリではなく、スクレイパーの設定(Wikipedia language)で指定します。

クエリの置換

クエリを増殖させるために、内蔵マクロを使用できます。

結果の出力例

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

リンクのリスト(デフォルト)

結果のフォーマット:

$serp.format('$link\n')

結果の例:

https://en.wikipedia.org/wiki/Albert_Einstein
https://en.wikipedia.org/wiki/Hans_Albert_Einstein
https://en.wikipedia.org/wiki/Religious_and_philosophical_views_of_Albert_Einstein
https://en.wikipedia.org/wiki/Albert_Brooks
https://en.wikipedia.org/wiki/Einstein_family

結果のフォーマット:

$serp.format('$link\t$anchor\t$snippet\n')

結果の例:

https://en.wikipedia.org/wiki/Albert_Einstein   Albert Einstein 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...
https://en.wikipedia.org/wiki/Hans_Albert_Einstein Hans Albert Einstein Hans Albert Einstein (May 14, 1904 – July 26, 1973) was a Swiss-American engineer, the second child and first son of physicists Albert Einstein and Mileva Marić. He was a professor of hydraulic engineering at the University of California, Berkeley from...
https://en.wikipedia.org/wiki/Religious_and_philosophical_views_of_Albert_Einstein Religious and philosophical views of Albert Einstein Albert Einstein's religious views have been widely studied and often misunderstood. Albert Einstein stated "I believe in Spinoza's God". He did not believe in a personal God who concerns himself with fates and actions of human beings, a view which he...

CSVへの出力

結果のフォーマット:

[% FOREACH item IN p1.serp; tools.CSVline(item.link, item.anchor, item.snippet, item.description, item.image, item.pageid, item.size); END %]

ヘッダーテキスト:

リンク,タイトル,スニペット,説明,画像,Page ID,サイズ

結果の例:

https://en.wikipedia.org/wiki/Albert_Einstein,"Albert Einstein","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...","German-born theoretical physicist (1879–1955)",https://upload.wikimedia.org/wikipedia/commons/thumb/2/28/Albert_Einstein_Head_cleaned.jpg/330px-Albert_Einstein_Head_cleaned.jpg?utm_source=en.wikipedia.org&utm_campaign=api&utm_content=thumbnail,736,238698
https://en.wikipedia.org/wiki/Hans_Albert_Einstein,"Hans Albert Einstein","Hans Albert Einstein (May 14, 1904 – July 26, 1973) was a Swiss-American engineer, the second child and first son of physicists Albert Einstein and Mileva Marić. He was a professor of hydraulic engineering at the University of California, Berkeley from...","Swiss-American engineer and educator",https://upload.wikimedia.org/wikipedia/commons/c/c9/Hans-Albert-Einstein-1953.jpg?utm_source=en.wikipedia.org&utm_campaign=api&utm_content=thumbnail_unscaled,1373258,14371

JSONへのダンプ

結果のフォーマット:

[% FOREACH item IN p1.serp;
'{"link":"' _ item.link _ '","anchor":"' _ item.anchor _ '","snippet":"' _ item.snippet _ '"}\n';
END %]

結果の例:

{"link":"https://en.wikipedia.org/wiki/Albert_Einstein","anchor":"Albert Einstein","snippet":"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..."}
{"link":"https://en.wikipedia.org/wiki/Hans_Albert_Einstein","anchor":"Hans Albert Einstein","snippet":"Hans Albert Einstein (May 14, 1904 – July 26, 1973) was a Swiss-American engineer, the second child and first son of physicists Albert Einstein and Mileva Marić. He was a professor of hydraulic engineering at the University of California, Berkeley from..."}

設定可能な項目

パラメータ名デフォルト値説明
Pages count5検索ページ数(1から50まで)。各ページ最大20件の結果
Wikipedia languageenWikipediaの言語版(en, ru, de, ja, simple, be-tarask など)。言語版リスト
Snippet length250スニペットの文字数(150–1200)。API TextExtractsの最大値は1200
ヒント

Wikipedia APIは、深いページネーションにおいて重複する結果を返すことがあります。スクレイパーは pageid に基づいて重複を削除し、除外された件数をログに記録します。