С 2017 года Википедия предоставляет REST API с улучшенным кэшированием.
В документации вы можете найти следующий API, который идеально подходит для вашего случая использования. (как оно используется новой функцией предварительного просмотра страниц )
https://en.wikipedia.org/api/rest_v1/page/summary/Stack_Overflow
возвращает следующие данные, которые можно использовать для отображения суммы с небольшим эскизом:
{
"type": "standard",
"title": "Stack Overflow",
"displaytitle": "Stack Overflow",
"extract": "Stack Overflow is a question and answer site for professional and enthusiast programmers. It is a privately held website, the flagship site of the Stack Exchange Network, created in 2008 by Jeff Atwood and Joel Spolsky. It features questions and answers on a wide range of topics in computer programming. It was created to be a more open alternative to earlier question and answer sites such as Experts-Exchange. The name for the website was chosen by voting in April 2008 by readers of Coding Horror, Atwood's popular programming blog.",
"extract_html": "<p><b>Stack Overflow</b> is a question and answer site for professional and enthusiast programmers. It is a privately held website, the flagship site of the Stack Exchange Network, created in 2008 by Jeff Atwood and Joel Spolsky. It features questions and answers on a wide range of topics in computer programming. It was created to be a more open alternative to earlier question and answer sites such as Experts-Exchange. The name for the website was chosen by voting in April 2008 by readers of <i>Coding Horror</i>, Atwood's popular programming blog.</p>",
"namespace": {
"id": 0,
"text": ""
},
"wikibase_item": "Q549037",
"titles": {
"canonical": "Stack_Overflow",
"normalized": "Stack Overflow",
"display": "Stack Overflow"
},
"pageid": 21721040,
"thumbnail": {
"source": "https://upload.wikimedia.org/wikipedia/en/thumb/f/fa/Stack_Overflow_homepage%2C_Feb_2017.png/320px-Stack_Overflow_homepage%2C_Feb_2017.png",
"width": 320,
"height": 149
},
"originalimage": {
"source": "https://upload.wikimedia.org/wikipedia/en/f/fa/Stack_Overflow_homepage%2C_Feb_2017.png",
"width": 462,
"height": 215
},
"lang": "en",
"dir": "ltr",
"revision": "902900099",
"tid": "1a9cdbc0-949b-11e9-bf92-7cc0de1b4f72",
"timestamp": "2019-06-22T03:09:01Z",
"description": "website hosting questions and answers on a wide range of topics in computer programming",
"content_urls": {
"desktop": {
"page": "https://en.wikipedia.org/wiki/Stack_Overflow",
"revisions": "https://en.wikipedia.org/wiki/Stack_Overflow?action=history",
"edit": "https://en.wikipedia.org/wiki/Stack_Overflow?action=edit",
"talk": "https://en.wikipedia.org/wiki/Talk:Stack_Overflow"
},
"mobile": {
"page": "https://en.m.wikipedia.org/wiki/Stack_Overflow",
"revisions": "https://en.m.wikipedia.org/wiki/Special:History/Stack_Overflow",
"edit": "https://en.m.wikipedia.org/wiki/Stack_Overflow?action=edit",
"talk": "https://en.m.wikipedia.org/wiki/Talk:Stack_Overflow"
}
},
"api_urls": {
"summary": "https://en.wikipedia.org/api/rest_v1/page/summary/Stack_Overflow",
"metadata": "https://en.wikipedia.org/api/rest_v1/page/metadata/Stack_Overflow",
"references": "https://en.wikipedia.org/api/rest_v1/page/references/Stack_Overflow",
"media": "https://en.wikipedia.org/api/rest_v1/page/media/Stack_Overflow",
"edit_html": "https://en.wikipedia.org/api/rest_v1/page/html/Stack_Overflow",
"talk_page_html": "https://en.wikipedia.org/api/rest_v1/page/html/Talk:Stack_Overflow"
}
}
По умолчанию он выполняет перенаправления (так что /api/rest_v1/page/summary/StackOverflow
также работает), но это можно отключить с помощью ?redirect=false
Если вам нужен доступ к API из другого домена, вы можете установить заголовок CORS с помощью &origin=
(например, &origin=*
)
Обновление 2019: API, кажется, возвращает более полезную информацию о странице.