0

我正在使用简单的 html dom 解析器,我正在尝试从以下字符串中获取公司名称:

<a data-omniture="LIST:COMPANYNAME" href="/b/Elite+Heating+and+Plumbing+Services-Plumbers-Reading-RG46RA-901196207/index.html" itemprop="name"> Elite Heating &amp; Plumbing Services </a>

所以a标签之间的位。

我有以下代码:

<?php include_once('simple_html_dom.php');

$html = file_get_html('http://www.thelink.com/');

foreach($html->find('a') as $element) 
       echo $element->href . '<br>'; echo '</ul>';

?

此外,是否可以搜索 html5 数据内容,所以无论数据如何:链接中的信息

这将所有链接都带回来,但显然我不想要所有链接。

4

1 回答 1

0

是的,你会这样做:

$name = $html->find('a[itemprop=name]', 0)->text();

这不是 xpath 顺便说一句,它是 css。

于 2013-06-08T00:09:28.143 回答