使用DomDocuments,查找并返回ID的值

时间:2016-02-27 04:37:53

标签: php jquery class roblox

我有jquery,我可以运行和控制并找到元素。



$.get("http://www.roblox.com/groups/group.aspx?gid=2755722", function(webpage) {

  if ($(webpage).find("#ctl00_cphRoblox_rbxGroupFundsPane_GroupFunds .robux").length) {
    alert("Eureka I found it!")
  } else {
    alert("nope!")
  }

})

<div id="ctl00_cphRoblox_rbxGroupFundsPane_GroupFunds" class="StandardBox" style="padding-right:0">
  <b>Funds:</b> 
  <span class="robux" style="margin-left:5px">29</span>
  <span class="tickets" style="margin-left:5px">45</span>
</div>
&#13;
&#13;
&#13;

当我尝试使用函数运行它作为PHP并使用DomDocuments来处理它时,它在解码时不会返回任何内容。 (以下是课程的全部内容)

protected function xpath($url,$path)
{
    libxml_use_internal_errors(true);
    $dom = new DomDocument;
    $dom->loadHTML($this->file_get_contents_curl($url));
    $xpath = new DomXPath($dom);
    return $xpath->query($path);
}

public function GetGroupStats($id)
{

    $elements = array   (
        'Robux'       =>  "//span[@id='ctl00_cphRoblox_rbxGroupFundsPane_GroupFunds .robux']",
        'Tix'     =>  "//span[@id='ctl00_cphRoblox_rbxGroupFundsPane_GroupFunds .tickets']",

    );
    $data = array();

    foreach($elements as $name => $element)
    {
        foreach ($this->xpath('http://www.roblox.com/Groups/group.aspx?gid='.$id,$element) as $i => $node)
            $data[$name]    =   $node->nodeValue;
    }

    return $data;
}

//包含该类并运行该函数的文件(忽略登录的内容,因为这种情况不是必需的)

<?php
$randomstuffdude = include 'RApi.php';
$GetAccessToken = $_GET['token'];

 if ($GetAccessToken == "secrettoken6996") {
    $rbxBot = new Roblox();
    $rbxBot -> DoLogin();

    $StatsArray = $rbxBot->GetGroupStats(2755722);
    foreach ($StatsArray as $other => $array) {
        echo $other . ' : ' . $array . '  /  ';
    }
} else {
    echo "no";
}
?>

0 个答案:

没有答案