-4

我正在寻找 curl 代码,我可以在其中从另一个网页中拉取外部网站的 div。

例如:这是外部网站:http ://www.uberstrike.com/public_profile/2585774

我想从“user_info”类中提取数据。

我在 curl 中看到了很多代码,但没有一个可以工作。

4

2 回答 2

2

他们有一个 API。

示例代码(用下面的选择替换 url):

$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 ...
)
于 2013-08-28T05:10:21.013 回答
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
于 2013-08-28T05:17:03.747 回答