从一篇文章的维基百科中获取描述 [英] Fetch the description from wikipedia from an article
本文介绍了从一篇文章的维基百科中获取描述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过以下方式对维基百科进行 API 调用:http://en.wikipedia.org/w/api.php?action=parse&page=Petunia&format=xml,但 xml 中充满了 html 和 css 标签.
I am trying to make a API call to wikipedia through: http://en.wikipedia.org/w/api.php?action=parse&page=Petunia&format=xml, but the xml is full with html and css tags.
有没有办法只获取没有标签的纯文本?谢谢!
Is there a way to fetch only plain text without tags? Thanks!
*编辑 1:
$json = json_decode(file_get_contents('http://en.wikipedia.org/w/api.php?action=parse&page=Petunia&format=json'));
$txt = strip_tags($json->text);
var_dump($json);
显示为空.
推荐答案
问题得到部分解答这里
$url = 'http://en.wikipedia.org/w/api.php?action=parse&page=Petunia&format=json&prop=text';
$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_USERAGENT, "TestScript"); // required by wikipedia.org server
$c = curl_exec($ch);
$json = json_decode($c);
var_dump(strip_tags($json->{'parse'}->{'text'}->{'*'}))
我无法使用 file_get_contents
,但它可以与 cURL
配合使用.
I was not able to use file_get_contents
but it works fine with cURL
.
这篇关于从一篇文章的维基百科中获取描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文