从一个网页解析一些数据我没有什么问题。我正在尝试获取某些的类名div
。
例子:
< div class="stars b3"></div>
我只想保存在数组中b3
。是否有可能做到这一点?
谢谢!
看到这个:
<?php // http://stackoverflow.com/questions/4835300/php-dom-to-get-tag-class-with-multiple-css-class-name
$html = <<< HTML
<td class="pos" >
<a class="firstLink" href="Search/?List=200003000112097&sr=1" >
Firs link value
</a>
<br />
<a class="secondLink SecondClass" href="/Search/?KeyOpt=ALL" >
Second Link Value
</a>
</td
HTML;
$dom = new DOMDocument();
@$dom->loadHTML($html);
$dom->preserveWhiteSpace = false;
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate(
"/html/body//a[@class='secondLink SecondClass']"
);
echo $hrefs->item(0)->getAttribute('class');