PHP에서 특정 클래스의 div 태그 만 추출하는 방법을 알고 있습니까?PHP를 사용하여 특정 클래스로 div 태그 추출
<div class="abc">
</div>
<div class="def">
</div>
<div class="xyz">
</div>
div 만 class = "abc"와 함께 사용해야합니다. 어떻게 구현할 수 있습니까?
PHP에서 특정 클래스의 div 태그 만 추출하는 방법을 알고 있습니까?PHP를 사용하여 특정 클래스로 div 태그 추출
<div class="abc">
</div>
<div class="def">
</div>
<div class="xyz">
</div>
div 만 class = "abc"와 함께 사용해야합니다. 어떻게 구현할 수 있습니까?
당신이 원하는 것은 : XPath
<?php
$html = new DOMDocument();
@$html->loadHtmlFile('thepage.html');
$xpath = new DOMXPath($html);
$nodelist = $xpath->query("//*[contains(@class, 'abc')]");
foreach ($nodelist as $n){
echo $n->nodeValue."\n";
}
?>
[업데이트]
추가 된 새로운 XPath 쿼리는. 시도해보십시오.
[PHP에서 HTML을 구문 분석하기위한 최선의 방법] (http://stackoverflow.com/questions/3577641/how-to-parse-and-process-html-with-php)을 요청할 수 있지만 현재 NARQ입니다. – mario
DOM을 사용해보십시오. http://php.net/manual/en/book.dom.php –