【问题标题】:how to get a div from a external website using curl in php [closed]如何在php中使用curl从外部网站获取div [关闭]
【发布时间】:2013-08-31 01:09:22
【问题描述】:

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

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

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

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

【问题讨论】:

  • 请向我们展示您到目前为止所做的尝试。我们通常不会在没有 OP 工作的情况下提供完整的解决方案。关键是,如果您希望我们将时间和精力投入到答案中,请投入时间和精力来解决您的问题。

标签: php html curl


【解决方案1】:

他们有一个 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 ...
)

【讨论】:

  • 感谢真的很有帮助
【解决方案2】:

试试这个:

//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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-09
    • 2013-08-18
    • 2014-03-08
    • 1970-01-01
    • 1970-01-01
    • 2012-10-15
    • 1970-01-01
    相关资源
    最近更新 更多