Php Goutte-Get表列
我怎样才能只得到一列而不是整个表Php Goutte-Get表列,php,goutte,Php,Goutte,我怎样才能只得到一列而不是整个表 <table cellspacing="0" cellpadding="0" align="Center" rules="all" border="1"> <tbody> <tr> <td>Entity Name</td> <td>NV Business ID</td> <td>Status</td
<table cellspacing="0" cellpadding="0" align="Center" rules="all" border="1">
<tbody>
<tr>
<td>Entity Name</td>
<td>NV Business ID</td>
<td>Status</td>
<td>Type</td>
</tr>
<tr>
<td><a href="">GOOGLE</a></td>
<td><a href=""></a></td>
<td><a href="">Expired</a></td>
<td><a href="">Reserved Name</a></td>
</tr>
<tr>
<td><a href="">GOOGLE INC.</a></td>
<td><a href="">NV20161275322</a></td>
<td><a href="">Active</a></td>
<td><a href="">Foreign Corporation</a>
</td>
</tr>
</tbody>
</table>
实体名称
NV业务ID
地位
类型
以下是我的尝试:
$client = new Client();
$crawler = $client->request('GET', 'url');
$form = $crawler->selectButton('Search')->form();
$crawler = $client->submit($form, array(
...
));
$crawler->filter('table tr')->each(function ($node) {
print $node->text()."\n \n";
// print $node->filter('td')->text() . '<br />';
});
$client=newclient();
$crawler=$client->request('GET','url');
$form=$crawler->selectButton('Search')->form();
$crawler=$client->submit($form,array)(
...
));
$crawler->filter('table tr')->每个(函数($node){
打印$node->text()。“\n\n”;
//打印$node->filter('td')->text()。
;
});
它总是把整张桌子都还回来。
还尝试了stn,如tr[1]等
有人能帮忙吗
谢谢我找到了一个解决方案:
$node->filter('td')->eq(2)->text();
2表示第三列,因为它是[0,1,2,…]您可以使用DOMDocument从HTML获取数据
尝试以下代码:
$content = $crawler->filter( 'table' )->extract( array( '_text' ) );
$content = $crawler->filter( 'table' )->extract( array( '_text' ) );