使用PHP,如何使用MediaWiki API获取维基百科文章的第一段? [英] Using PHP, how do I get the first paragraph of a Wikipedia article with the MediaWiki API?
本文介绍了使用PHP,如何使用MediaWiki API获取维基百科文章的第一段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 PHP
从维基百科透过MediaWiki API取得任何文章的第一段?
How do I use PHP
to get the first paragraph of any article from Wikipedia through their MediaWiki API?
我对所有建议开放。很可能 CURL
或 XML
会派上用场。
I am open to all suggestions. Most probably CURL
or XML
will come in handy.
推荐答案
您可以这样使用API:
You can use the API as so:
http://en.wikipedia.org/w/api.php?action=parse&page=Stack_overflow&format=xml&prop=text§ion=0
这将返回一个结构为
<?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
这篇关于使用PHP,如何使用MediaWiki API获取维基百科文章的第一段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文