/**
* 处理最终内容
* @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) {
}
}
未经允许不得转载:互联网骚操作 » php的xpath采集表格table 获取td所有内容
评论前必须登录!