0
我試圖刮掉每個.row的href。最終,我想點擊鏈接並訪問它鏈接的DOM,但我無法獲得Link對象或href屬性。無法選擇鏈接
不確定a屬性是否有任何文本是一個問題,但這是我必須與之合作的DOM。
幫助?
<?php require 'vendor/autoload.php';
use Symfony\Component\DomCrawler\Crawler;
$html = <<<'HTML'
<!doctype html>
<html>
<body>
<div class="content">
<p class="row"><a href="/uri1"></a></p>
<p class="row"><a href="/uri2"></a></p>
<p class="row"><a href="/uri3"></a></p>
</div>
</body>
<html>
HTML;
$dom = new Crawler($html);
$content = $dom->filter('.row');
$rows = [];
foreach ($content as $element)
{
$node = new Crawler($element);
$link = $node->filter('a');
echo $link->html(); // Empty?
try
{
$link = $node->selectLink('')->link();
echo $link->getUri();
}
catch (Exception $ex)
{
// Throws: Current URI must be an absolute URL ("").Current URI must be
// an absolute URL ("").Current URI must be an absolute URL ("").
echo $ex->getMessage();
}
}