我想解析使用CURL获得的数据,以从结果中获取有用的信息

时间:2011-01-03 16:55:27

标签: php curl html-parsing

在指导下,我正在全面详细地转发这个问题。代码的目的是从远程服务器检索结果并将其存储到我的数据库,然后在用户需要时从我的服务器数据库中显示它。

我想从网站上检索单个对象和标记。     

curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_POST, true);
curl_setopt($request, CURLOPT_POSTFIELDS, array('rid' => '1kn06cs032','submit' =>   'SUBMIT'));

if(!($result = curl_exec($request)))
    die('curl_exec failed with error: '.curl_error($request));

curl_close($request);

//echo strip_tags($result,'<tr><b><td>') ;
  $s=strip_tags($result,'') ;
//strstr($s,")");
  $t=strstr($s,"(PROVISIONAL)");
   echo $t;
   //$a=explode('Semester:',$t);
   //echo $a[0];
   //echo $a[1];

 ?> 

请指导我,因为我已经尝试了许多替代方案,因为我对解析和php的基本知识知之甚少,所以我已经尝试了很多替代方案。

帮助将受到高度赞赏。

谢谢

2 个答案:

答案 0 :(得分:0)

这仍然不够信息。您从此Curl调用中获得的输出将非常有用。

可能值得研究PHP的DomDocumentDomXpath这将允许您使用Xpath的查询语言查询HTML和XML

例如:

$dom = new DomDocument();
$dom->loadHTMLFile(HTML_FROM_CURL_HERE);
$xpath = new DOMXpath();

// Get all divs
$divs = $xpath->query("//div");

// Get the div with the id of 'container' which is direct child of the body element
$container = $xpath->query("/body/div[id='container']");

我希望能让你开始。

杰克

答案 1 :(得分:0)

use this method to parse the data 

$result = curl_exec($request);  

$json_a1=json_decode($result,true);
$json_o1=json_decode($result);

foreach($json_o1->data as $p1)
{
    echo $p1->id;
}
相关问题