我正在尝试使用DOMCrawler 过滤我的html,但如果找到结果,我需要中断。
有可能打破each
吗?或者如果我使用
我怎么能得到?还是不可能?$node->text();
foreach
HTML:
<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>
PHP:
$client = new Client();
$client->setHeader('User-Agent', "Opera/9.80 (Windows NT 6.2; Win64; x64) Presto/2.12.388 Version/12.15");
$crawler = $client->request('GET', 'http://nvsos.gov/sosentitysearch/');
$form = $crawler->selectButton('Search')->form();
$crawler = $client->submit($form, array(
'ctl00$MainContent$txtSearchBox' => 'google',
));
if($this->available == false)return;
$crawler->filter('table tr')->each(function (\Symfony\Component\DomCrawler\Crawler $element) {
$status = $element->filter('td')->eq(2)->text();
echo $status;
if ($status == 'Active') {
$this->available = false;
break;
}
});
我想获得状态。然后如果状态等于“活动”,我想打破循环。
好的,现在我想出了一些东西。
$crawler = $crawler->filter('#ctl00_MainContent_objSearchGrid_dgCorpSearchResults');
foreach ($crawler as $i => $content) {
$crawler = new Crawler($content);
foreach ($crawler->filter('#ctl00_MainContent_objSearchGrid_dgCorpSearchResults') as $node) {
$longStatus = $node->nodeValue;
echo $longStatus;
}
}
但现在我不知道如何才能获得第三名<td>
。<tr>