接入教程
https://zh.wikipedia.org/api/rest_v1/page/summary/地球https://zh.wikipedia.org/api/rest_v1/search/page?q=人工智能1. 直接请求页面摘要:
2. 搜索页面:
3. 支持英文与中文等各语言版本。
4. 返回JSON包含标题、摘要与图片信息。
5. 免费无需Key,请控制请求频率并设置User-Agent。
Python 获取百科摘要
python
import requests
headers = {"User-Agent": "MyApp/1.0"}
r = requests.get("https://zh.wikipedia.org/api/rest_v1/page/summary/地球", headers=headers)
print(r.json()["extract"])
PHP 获取百科摘要
php
<?php
$ctx = stream_context_create(['http' => ['header' => "User-Agent: MyApp/1.0\r\n"]]);
$data = json_decode(file_get_contents('https://zh.wikipedia.org/api/rest_v1/page/summary/地球', false, $ctx), true);
echo $data['extract'];
JavaScript 获取百科摘要
javascript
fetch('https://zh.wikipedia.org/api/rest_v1/page/summary/地球', {headers: {'User-Agent': 'MyApp/1.0'}})
.then(r => r.json())
.then(d => console.log(d.extract));
常见问题
需要Key吗?
不需要,维基百科REST接口免费开放且无需认证。
有什么使用建议?
建议设置User-Agent并控制请求频率(每客户端200次/秒内)。
Aitishiku.com