2009-07-25 4 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にすることもできます。

関連する問題