表中的Querypath Extract元素

时间:2012-11-07 14:02:18

标签: php querypath

我正在使用Querypath从表中提取名称和位置信息。我已经能够使用innerhtml()提取表本身,但现在我正在尝试将文本收集到变量中。这是我的代码:

$searchpage = my_curl($mypage);
$searchqp = htmlqp($searchpage,'body');
$storeinfo = $searchqp->branch()->find('table[class="kwrestuls_table"]');
$storename = $storeinfo->innerhtml();
return $storename;

这给了我所需的核心信息。现在我需要抓住商店名称。我尝试过使用:

$storeinfo = $searchqp->branch()->find('table[class="kwrestuls_table"]');
$storestuff = $storeinfo->innerhtml();
$storename = $storestuff->top('a[href]')->attr('href')->text();
return $storename;

但这不会返回任何东西。不幸的是我在共享主机上,我看不到错误,但我怀疑QueryPath正在抛出一个。

1 个答案:

答案 0 :(得分:0)

我使用以下代码完成了我的专长:

$searchqp = htmlqp($searchpage,'body');
$storeinfo = $searchqp->branch()->find('table[class="kwrestuls_table"]');
$storestuff = $storeinfo->innerhtml();
$storename = htmlqp($storestuff, 'a')->eq(0)->text();
$storeaddress = htmlqp($storestuff, 'div')->eq(0)->text();
$storephones = htmlqp($storestuff, 'div')->eq(1)->text();
return $storephones;