Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save brunomoraes/577cf1dff8454f074a634f4bf9d1f0e2 to your computer and use it in GitHub Desktop.
Save brunomoraes/577cf1dff8454f074a634f4bf9d1f0e2 to your computer and use it in GitHub Desktop.
try{
$tr_elements = $crawler2->filterXPath('//table/tr');
$result = $crawler2->filter('#ctl00_ContentPlaceHolder1_dlResultados')->html();
//$element = $crawler2->filter("#ctl00_ContentPlaceHolder1_dlResultados > span")->text();
$crawler3 = new Crawler($result);
//$elements = $crawler3->filter('.resultadocdital')->html();
$node = $crawler3->filter('.resultadocdital')->each(function (Crawler $node, $i) {
$PATTERN = '/\<strong\>(?<name>[^\<^\>]*)\s?:\s?<\/strong\>(?<content>[^\<^\>]*)/m';
preg_match_all($PATTERN, trim($node->html()), $matches, PREG_SET_ORDER, 0);
if (!isset($matches[0])) {
//continue;
}
//echo PHP_EOL, '---------', PHP_EOL;
$match = $matches[0];
$value = $this->clear($match['content']);
//echo PHP_EOL, "{$match['name']} => '{$value}'", PHP_EOL;
foreach ([0, 1, 2, 3, 4, 5, 6, 7, 8] as $key) {
if (!isset($matches[$key])) {
continue;
}
$match = $matches[$key];
$id = $this->clear($match['name']);
$value = $this->clear($match['content']);
$dadosHeader = [];
$dadosHeader[] = [
'name' => $this->clear($match['name']),
'content' => $this->clear($match['content']),
];
return $dadosHeader;
//echo PHP_EOL, "{$match['name']} => '{$value}'", PHP_EOL;
}
});
// $crawlerHref = new Crawler($result);
// $crawlerHref->filter('a')->each(function (Crawler $node, $i) {
// $href = $node->attr('href');
// });
// return $result;
}catch(\InvalidArgumentException $e){
return "error";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment