2009-07-25 2 views
0

나는 simplehtmldom을 사용하여 웹 스크래퍼를 쓰려고합니다. 태그의 내용을 검색하여 태그를 얻고 싶습니다. 이것은 내부에있는 평문이며 태그 유형은 아닙니다. 그런 다음 일반 텍스트의 내용을 검색하여 태그를 얻은 후에는 그 다음 태그를 가져오고 싶습니다.simplehtmldom에서 태그의 내용으로 어떻게 검색합니까?

내용을 기준으로 태그를 찾는 방법은 무엇입니까? 일단 내가 가지고 있으면 다음과 같은 태그를 어떻게 찾을 수 있습니까?

도움을 주시면 감사하겠습니다.

감사합니다.

답변

0

다음은 다음 태그를 한 후, 모든 텍스트 노드를 검색 얻을 수있게된다 :

// Use Simple_HTML_DOM special selector 'text' 
// to retrieve all text nodes from the document 
$textNodes = $html->find('text'); 
$foundTag = null; 

foreach($textNodes as $textNode) { 
    if($textNode->plaintext == 'Hello World') { 
     // Get the parent of the text node 
     // (A text node is always a child of 
     // its container) 
     $foundTag = $textNode->parent(); 
     break; 
    } 
} 

if($foundTag) { 
    $nextTagAfter = $foundTag->next_sibling(); 
} 

이 기본 Simple_HTML_DOM 사용에 대한 귀하의 첫 번째 질문이 아니다. read the official documentation을 원할 수도 있습니다.