0

我如何PHP通过他们的 MediaWiki API 从维基百科获取任何文章的第一段?

我愿意接受所有建议。很可能CURLXML将派上用场。

4

2 回答 2

2

您可以这样使用 API:

http://en.wikipedia.org/w/api.php?action=parse&page=Stack_overflow&format=xml&prop=text&section=0

这将返回一个具有以下结构的 xml 文件:

<?xml version="1.0"?>
<api>
  <parse title="Article Title">
    <text xml:space="preserve">Text you wanted goes here</text>
  </parse>
</api>

注意变量:page=Article_Title_Goes_Here format=xml prop=text

于 2013-06-29T11:22:46.577 回答
-3

我会用file_get_contents('http://wikipedia.com/'.$rest_of_url)

然后只需使用字符串解析来选择所有表单

http://php.net/manual/en/function.substr.php

于 2012-02-21T17:28:35.970 回答