世界那么大,我带你去看看

php的xpath采集表格table 获取td所有内容

/**

* 处理最终内容

* @param unknown $url

*/

function parseContent($url)

{

$html = httpGet($url);

$rules = ‘//table[@class=”t_table”]/..//tr’;

try {

$dom = new \DOMDocument();

// load html into document object model

@$dom->loadHTML($html);

// create domxpath instance

$xPath = new \DOMXPath($dom);

// get all elements with a particular id and then loop through and print the href attribute

$elements = $xPath->query($rules);

$list = [];

foreach ($elements as $k=>$v)

{

$item = [];

foreach($v->childNodes as $kk=>$vv){

$item[] = $vv->nodeValue;

}

$list[] = $item;

}

dump($list);

}catch (Exception $e) {

}

}

未经允许不得转载:周游World » php的xpath采集表格table 获取td所有内容

分享到:更多 ()

评论 抢沙发

评论前必须登录!

世界那么大,跟着我去看看

联系我们联系我们