SE::Wikipedia - công cụ cào dữ liệu tìm kiếm Wikipedia
Tổng quan về công cụ cào dữ liệu
Công cụ cào dữ liệu kết quả tìm kiếm Wikipedia. Cho phép tìm kiếm các bài viết trên bách khoa toàn thư theo từ khóa thông qua MediaWiki Action API chính thức và nhận kết quả có cấu trúc: liên kết, tiêu đề, đoạn trích (snippet), mô tả ngắn, xem trước hình ảnh, ID trang và kích thước bài viết.
Hỗ trợ tất cả các phiên bản ngôn ngữ của Wikipedia (en, ru, de, ja, simple, be-tarask, v.v.). Trên một trang kết quả — tối đa 20 kết quả (giới hạn của API extracts), phân trang — lên đến 50 trang. Các kết quả trùng lặp giữa các trang sẽ tự động được lọc bỏ.
Tính năng của A-Parser cho phép lưu các thiết lập cào dữ liệu để sử dụng sau này (mẫu thiết lập), đặ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 dưới 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.
Để lấy toàn bộ nội dung văn bản của bài viết, hãy sử dụng công cụ cào dữ liệu SE::Wikipedia::Article.
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 (generator=search).
- Tổng số lượng kết quả (
totalcount) - Liên kết đến bài viết
- Tiêu đề (anchor)
- Đoạn trích (trích xuất văn bản thuần túy)
- Mô tả ngắn (description)
- Xem trước hình ảnh (nếu có)
- Page ID
- Kích thước bài viết (byte)
Tính năng
- Tìm kiếm theo bất kỳ phiên bản ngôn ngữ nào của Wikipedia (danh sách các phiên bản)
- Tùy chỉnh độ dài đoạn trích (lên đến 1200 ký tự — tối đa của MediaWiki TextExtracts)
- Phân trang lên đến 50 trang × 20 kết quả
- Tự động khử trùng lặp bài viết giữa các trang kết quả
- Hỗ trợ Proxy và các thiết lập chung của A-Parser
Ứng dụng
- Thu thập cơ sở dữ liệu liên kết đến các bài viết Wikipedia
- Lựa chọn các bài viết liên quan theo từ khóa cho nội dung và SEO
- Lấy đoạn trích và mô tả cho chatbot và các hệ thống tra cứu
- Phân tích sâu hơn các bài viết thông qua SE::Wikipedia::Article
Truy vấn
Trong phần truy vấn, bạn cần chỉ định các cụm từ tìm kiếm, ví dụ:
Albert Einstein
Ivan Efremov
Berlin
東京
Kyiv
Ngôn ngữ tìm kiếm được thiết lập trong cài đặt của công cụ cào dữ liệu (Wikipedia language), chứ không phải trong truy vấn.
Thay thế truy vấn
Bạn có thể sử dụng các macro tích hợp sẵn để nhân bản các truy vấn.
Các ví dụ về định dạng kết quả
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ạng tùy ý, cũng như ở dạng có cấu trúc như CSV hoặc JSON.
Danh sách liên kết (mặc định)
Định dạng kết quả:
$serp.format('$link\n')
Ví dụ kết quả:
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
Liên kết + Tiêu đề + Đoạn trích
Định dạng kết quả:
$serp.format('$link\t$anchor\t$snippet\n')
Ví dụ kết quả:
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...
Xuất ra CSV
Định dạng kết quả:
[% FOREACH item IN p1.serp; tools.CSVline(item.link, item.anchor, item.snippet, item.description, item.image, item.pageid, item.size); END %]
Văn bản bắt đầu:
Liên kết,Tiêu đề,Đoạn trích,Mô tả,Hình ảnh,Page ID,Kích thước
Ví dụ kết quả:
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
Xuất ra JSON
Định dạng kết quả:
[% FOREACH item IN p1.serp;
'{"link":"' _ item.link _ '","anchor":"' _ item.anchor _ '","snippet":"' _ item.snippet _ '"}\n';
END %]
Ví dụ kết quả:
{"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..."}
Các thiết lập có thể có
| Tên tham số | Giá trị mặc định | Mô tả |
|---|---|---|
| Pages count | 5 | Số lượng trang tìm kiếm (từ 1 đến 50). Mỗi trang có tối đa 20 kết quả |
| Wikipedia language | en | Phiên bản ngôn ngữ của Wikipedia (en, ru, de, ja, simple, be-tarask và các ngôn ngữ khác). Danh sách các phiên bản |
| Snippet length | 250 | Độ dài đoạn trích tính bằng ký tự (150–1200). Tối đa của API TextExtracts là 1200 |
API Wikipedia khi phân trang sâu có thể trả về các kết quả trùng lặp. Công cụ cào dữ liệu sẽ xóa các bản trùng lặp theo pageid và ghi vào nhật ký số lượng đã được loại bỏ.