这是我拥有的代码,我想获取该 id 的 href 值
function file_get_contents_curl($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$str = 'someLink';
$html = file_get_contents_curl($str);
$doc = new DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTML('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' . $html);
libxml_clear_errors();
$nodes = $doc->getElementsByTagName('title');
$hrefValue = $doc->getElementById('linker');
someLink html 示例:
<html>
<head>
<title></title>
</head>
<body>
<div>one</div>
<div>two</div>
<div>
<a href="link" id="linker" />LINK HERE</a>
</div>
</body>
</html>
我想获取 id="linker" 的 href 值。我尝试使用 getElementById() 但它没有返回任何内容