2013-08-28 64 views
-4

我正在尋找捲曲代碼,在該代碼中,我可以從外部網站獲取div,並將其從另一個網頁中拉出。如何從外部網站使用curl在php中獲取div

例如:這是外部網站:http://www.uberstrike.com/public_profile/2585774

,我想從類「USER_INFO」拉取數據。

我已經看到了很多捲曲代碼,然後沒有工作。

+1

請告訴我們你試過到目前爲止。我們通常不會提供完整的解決方案,而沒有OP的工作。關鍵在於,如果您希望我們把時間和精力投入到答案中,請將時間和精力投入到您的問題中。 – Daedalus

回答

2

他們有一個API。

實施例的代碼(替換下面的選擇鏈接):

$json = json_decode(file_get_contents('http://www.uberstrike.com/profile/all_stats/2585774'), true); 
print_r($json); 

成績:http://www.uberstrike.com/profile/all_stats/2585774

Array 
(
    [headshots_record] => 146 
    [nutshots_record] => 91 
    [damage_dealt_record] => 27060 
    [damage_received_record] => 32695 
    ... truncated ... 
) 

用戶信息:http://www.uberstrike.com/profile/user_info/2585774

Array 
(
    [name] => deadbodies 
    [level] => 80 
    [xp] => 5587757 
    [clan_name] => E-PIPE 
    [clan_tag] => EPIPE 
    [accesslevel] => 0 
    [creation_date] => 2011-08-17T06:40:07Z 
) 

其他東西:http://www.uberstrike.com/profile/user_loadout/2585774

Array 
(
    [weapon_1] => 1243 
    [weapon_2] => 1656 
    [weapon_3] => 1370 
    [melee_weapon] => 0 
    [holo] => 1716 
    [upper_body] => 1644 
    [lower_body] => 1567 
    ... truncated ... 
) 
+0

非常感謝 –

1

試試這個:

//CURL 
$ch = curl_init(); 
$timeout = 5; // set to zero for no timeout 
curl_setopt ($ch, CURLOPT_URL, 'WEBSITE_URL');//enter your url here 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 

$file_contents = curl_exec($ch); //get the page contents 
preg_match($s_searchFor, $file_contents, $matches); //match the element 
$file_contents = $matches[0]; //set the file_contents var to the matched elements