0
私は以下InvalidArgumentException - The current node list is empty.
のようなイム取得中にエラーが、それは別のものを与え始めInvalidArgumentException - 現在のノードリストが空です。
if ($crawler->filter('div#links.results')->count() > 0) {
$string = $crawler->filter('div#links.results')->html()
}
以下のように私は解決策を使用してみました
$string = $crawler->filter('div#links.results')->html();
if (empty($string))
return false;
$dom = new \DOMDocument;
$state = libxml_use_internal_errors(true);
$dom->loadHTML($string);
libxml_use_internal_errors($state);
$xp = new \DOMXPath($dom);
$divNodeList = $xp->query('//div[contains(@class, "results_links_deep")]
[contains(@class, "web-result")]
/div[contains(@class, "links_main")]
[contains(@class, "links_deep")]
[contains(@class, "result__body")]');
$results = [];
if(count($divNodeList) > 0){
foreach ($divNodeList as $divNode) {
$results[] = [
trim($xp->evaluate('string(./h2/a[@class="result__a"])', $divNode)),
trim($xp->evaluate('string(.//a[@class="result__snippet"])', $divNode)),
trim($xp->evaluate('string(.//a[@class="result__url"])', $divNode))
];
}
}
を使用してイムコードで、データをこすりするグットのsracperを使用していますエラーのようなエラーDOMDocument::loadHTML(): Empty string supplied as input
お願いします。