Chuyển đến nội dung chính

SE::Wikipedia::Article - công cụ cào dữ liệu bài viết Wikipedia

Tổng quan về công cụ cào dữ liệu

Công cụ cào dữ liệu bài viết Wikipedia. Đầu vào là một liên kết đến bài viết (hoặc định dạng ngắn lang:title), đầu ra là toàn bộ nội dung bài viết dưới dạng văn bản thuần túy (plain text), mô tả ngắn gọn, liên kết chuẩn (canonical link), ảnh thu nhỏ (thumbnail) và ảnh gốc, danh mục, các phiên bản ngôn ngữ, Wikidata ID và siêu dữ liệu phiên bản.

Dữ liệu được lấy thông qua MediaWiki Action API chính thức (prop=extracts|info|pageimages|...). Ngôn ngữ được xác định từ URL hoặc tiền tố của truy vấn. Các chuyển hướng (redirect) của Wikipedia được xử lý tự động (ví dụ: USAUnited States).

Để tìm kiếm bài viết theo từ khóa, hãy sử dụng công cụ cào dữ liệu SE::Wikipedia.

Tính năng của A-Parser cho phép lưu các cài đặt cào dữ liệu để sử dụng sau này (mẫu thiết lập sẵn), đặt lịch trình cào dữ liệu và nhiều tính năng khác. Việc lưu kết quả có thể thực hiện theo bất kỳ hình thức và cấu trúc nào bạn cần, nhờ vào bộ tạo mẫu mạnh mẽ được tích hợp sẵn Template Toolkit.

Dữ liệu thu thập được

Dữ liệu được thu thập thông qua API https://{lang}.wikipedia.org/w/api.php.

  • Tiêu đề bài viết (title)
  • Mô tả ngắn gọn (description)
  • Toàn bộ nội dung bài viết dưới dạng văn bản thuần túy (text)
  • Liên kết chuẩn (link)
  • Ảnh xem trước (thumb)
  • Ảnh gốc (image)
  • Page ID (pageid)
  • Kích thước bài viết tính bằng byte (size)
  • Ngôn ngữ của ấn bản (lang)
  • Wikidata ID (wikidata)
  • Thời gian của phiên bản cuối cùng (timestamp)
  • ID phiên bản (revid)
  • Danh sách các danh mục (categories)
  • Các phiên bản ngôn ngữ của bài viết (langlinks: lang, title, link)
  • JSON thô từ phản hồi API (data)

Tính năng

  • Phân tích các liên kết Wikipedia dạng desktop, mobile và index.php
  • Định dạng truy vấn ngắn lang:title
  • Tự động theo dõi các chuyển hướng
  • Lấy toàn bộ văn bản thuần túy của bài viết (không có HTML/Markdown)
  • Danh mục và liên kết ngôn ngữ với giới hạn API max (lên đến 500)
  • Hỗ trợ Proxy và các cài đặt chung của A-Parser

Ứng dụng

  • Trích xuất văn bản bài viết cho NLP, RAG và cơ sở tri thức
  • Thu thập mô tả và hình ảnh cho thẻ thông tin và bot
  • Lấy danh mục và các phiên bản ngôn ngữ của trang
  • Làm phong phú kết quả tìm kiếm của SE::Wikipedia bằng nội dung đầy đủ của bài viết

Truy vấn

Các định dạng truy vấn được hỗ trợ:

  1. Liên kết tiêu chuẩn:
https://en.wikipedia.org/wiki/Albert_Einstein
https://ru.wikipedia.org/wiki/Ефремов,_Иван_Антонович
  1. Liên kết di động:
https://en.m.wikipedia.org/wiki/Albert_Einstein
  1. Liên kết dạng index.php:
https://en.wikipedia.org/w/index.php?title=Albert_Einstein
  1. Với neo phần (#... bị bỏ qua):
https://en.wikipedia.org/wiki/Albert_Einstein#Scientific_career
  1. Định dạng ngắn lang:title:
en:Albert Einstein
vi:Efremov, Ivan Antonovich
eo:Esperanto

Ngoài ra, các URL-encoding, dấu _ trong tiêu đề, chuyển hướng và mã ngôn ngữ có dấu gạch ngang (be-tarask) cũng được xử lý chính xác.

Các ví dụ về kết quả đầu ra

A-Parser hỗ trợ định dạng kết quả linh hoạt nhờ bộ tạo mẫu tích hợp Template Toolkit, cho phép xuất kết quả dưới dạng tùy ý, cũng như ở dạng cấu trúc như CSV hoặc JSON.

Đầu ra mặc định

Định dạng kết quả:

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

Ví dụ kết quả:

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

Định dạng kết quả:

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

Ví dụ kết quả:

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

Xuất ra CSV

Định dạng kết quả:

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

Văn bản bắt đầu:

Tiêu đề,Mô tả,Liên kết,Page ID,Wikidata,Ngôn ngữ,Kích thước

Ví dụ kết quả:

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

Danh mục

Định dạng kết quả:

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

Ví dụ kết quả:

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

Định dạng kết quả:

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

Ví dụ kết quả:

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

Xuất ra JSON

Định dạng kết quả:

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

Ví dụ kết quả:

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

Các cài đặt có thể có

Công cụ cào dữ liệu này không có tùy chọn riêng biệt trong giao diện người dùng (UI): ngôn ngữ và tiêu đề được lấy từ truy vấn. Chỉ sử dụng cài đặt chung (proxy, số lần thử lại, v.v.).