我正在尝试使用 Curl 从 Wikipedia 获取页面摘要。我的代码是
<?php
$title = <input from user>;
$url = 'http://en.wikipedia.org/w/api.php?action=query&titles='.$title.'&format=xml&prop=revisions&rvprop=content&redirects';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_USERAGENT, 'testing wikipedia services');
$result = curl_exec($curl);
print $result;
//$content = $c->query->pages->page->revisions->rev;
//print $content;
?>
我最初想测试代码以查看我的代码是否返回整个页面。但我收到一个错误,上面写着
请求:[未知方法] http://en.wikipedia.org:80/w/api.php?action=query&titles=US Environmental Protection Agency&format=xml&prop=revisions&rvprop=content&redirects, from 161.80.8.53 via cp1005.eqiad.wmnet ( squid/2.7.STABLE9) 到 [unknown host] ([unknown]) 错误:ERR_INVALID_URL, errno [No Error] 2012 年 12 月 4 日星期二 16:55:52 GMT
该 URL 有效,但仍会产生未知方法错误!