我正在嘗試使用MediaWiki獲取維基百科頁面(來自特定類別)。爲此,我正在關注this教程清單3.列出類別中的頁面。我的問題是:如何在不使用Zend Framework的情況下獲取Wikipedia頁面?有沒有基於PHP的休息客戶端,而無需安裝?因爲Zend需要首先安裝他們的軟件包,並且需要一些配置......我不想完成所有這些工作。將維基百科API與其他客戶端一起使用
谷歌搜索和一些調查後,我發現了一個名爲cURL的工具,使用PHP的cURL也可以建立一個休息服務。我在執行休息服務真的很新,但已經試圖在PHP中實現的東西:
<?php
header('Content-type: application/xml; charset=utf-8');
function curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$wiki = "http://de.wikipedia.org/w/api.php?action=query&list=allcategories&acprop=size&acprefix=haut&format=xml";
$result = curl($wiki);
var_dump($result);
?>
,但得到的結果的誤差。任何人都可以提供幫助嗎?
UPDATE:
This page contains the following errors:
error on line 1 at column 1: Document is empty
Below is a rendering of the page up to the first error.
如果你告訴我們錯誤是什麼,它可能會有所幫助。 – 2013-03-14 19:53:12
@IlmariKaronen請看看問題的'update'部分。 – Dozent 2013-03-14 20:48:21