PHP简单HTML DOM解析器。“不返回”;href";来自锚定标记的属性
我试图从html源获取所有URL,但是返回的有效负载不带“href”属性 这是我的代码:PHP简单HTML DOM解析器。“不返回”;href";来自锚定标记的属性,php,parsing,simple-html-dom,Php,Parsing,Simple Html Dom,我试图从html源获取所有URL,但是返回的有效负载不带“href”属性 这是我的代码: include('simple_html_dom.php'); $foundHits = array(); getArticles('https://pinpoint.microsoft.com/pt-PT/search?keyword=azure'); function getArticles($page) { global $foundHits; $html = new simp
include('simple_html_dom.php');
$foundHits = array();
getArticles('https://pinpoint.microsoft.com/pt-PT/search?keyword=azure');
function getArticles($page) {
global $foundHits;
$html = new simple_html_dom();
$html->load_file($page);
$hits = $html->find('div[class="companySearchResults"] div[class="itemRight"] a[class=searchResult]');
foreach($hits as $hit) {
$foundHits[] = $hit->attr['href'];
}
var_dump($foundHits);
}
这是一个如果I var_dump$hits变量返回的示例:
array (size=2)
0 =>
object(simple_html_dom_node)[447]
public 'nodetype' => int 1
public 'tag' => string 'a' (length=1)
public 'attr' =>
array (size=2)
'data-bind' => string 'href: uri + '?id=searchResult'' (length=30)
'class' => string 'searchResult' (length=12)
public 'children' =>
(...)
您可以看到,在“attr”数组中,我没有得到href标记内容,尽管存在
但是,如果我将源URL中的内容复制到项目文件夹中的.html,并将此local.html用作源文件,则结果如下:
0 =>
object(simple_html_dom_node)[650]
public 'nodetype' => int 1
public 'tag' => string 'a' (length=1)
public 'attr' =>
array (size=3)
'data-bind' => string 'href: uri + '?id=searchResult'' (length=30)
'class' => string 'searchResult' (length=12)
'href' => string '/pt-PT/Companies/4295470302?id=searchResult' (length=43)
(...)
我做错了什么?谢谢你的帮助 您应该包含一个html代码段,并尝试缩小问题的范围。您应该包含一个html代码段,并尝试缩小问题的范围。您应该包含一个html代码段,并尝试缩小问题的范围。