【发布时间】:2011-04-12 15:25:11
【问题描述】:
我希望使用他们的 api 检索 Wikipedia 页面的 XML。我使用的网址如下:http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xml&redirects&titles=dog
我见过this,但没有帮助。无论我做什么,我实际上都没有得到任何返回到 $c 的东西,我不知道为什么。我可以用纯文本文件做file_get_contents,它工作得很好。其他人可以验证这是否有效吗?
<?php
$url = 'http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xml&redirects&titles=Main%20Page';
$c = file_get_contents($url);
echo $c;
?>
编辑我也尝试了该页面上可用的 cURL,但也不起作用:
$url = 'http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xml&redirects&titles=Main%20Page';
$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$c = curl_exec($ch);
echo $c;
【问题讨论】:
-
您的托管公司可能在 file_get_contents 上禁用了 URL,您是否尝试过 curl?
-
Warning: file_get_contents(http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xml&redirects&titles=Main%20Page) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden in [file] -
我也尝试过 curl,但我也无法开始工作。我已经把它贴在上面供参考了。