我需要打開以下網址如何使用fopen()打開遠程文件?
$file = "http://en.wikipedia.org/w/api.php?action=parse&page=Kundapura&prop=text&format=xml";
$fp = fopen($file, "r");
,但我geeting警告HTTP請求失敗禁止/ 403
我需要打開以下網址如何使用fopen()打開遠程文件?
$file = "http://en.wikipedia.org/w/api.php?action=parse&page=Kundapura&prop=text&format=xml";
$fp = fopen($file, "r");
,但我geeting警告HTTP請求失敗禁止/ 403
你有什麼需要的文件嗎?如果您只需要輸出,則可以嘗試使用file_get_contents(),然後將其作爲字符串而不是文件加載和操作。
我需要解析它的應用程序 – Raghs 2011-04-01 05:59:54
默認的PHP用戶代理被阻止;詳情請參見Wikimedia's User-Agent policy。你可以很輕鬆地更改使用ini_set
您的用戶代理在腳本的頂部,這樣的:
ini_set("user_agent", "Testing for http://stackoverflow.com/questions/5509640");
請注意,英文維基百科不允許對通過API下載很多網頁(提供database dumps代替),而自動化流程除非approved禁止實際編輯Wiki。有關詳細信息,請參閱their bot policy。
@blueshift,那是[簡單地不正確](http://us2.php.net/manual/en/wrappers.php)。默認配置包括十幾種不同的包裝,包括HTTP。 – Charles 2011-04-01 06:15:18
@Charles哦,你是對的。也許我應該堅持C問題.. – blueshift 2011-04-01 08:29:41