1

プレーンテキストを内部から取得しようとしています<font size="3" color="blue">...フォントタグを取得しませんが、「フォント」を実行すると機能します3が、サイトにはフォントタグがたくさんあるので、検索をもう少し具体的にします。タグに複数の属性を含めることは可能ですか?

<?php

include('simple_html_dom.php');

$html = new simple_html_dom();   
$html = file_get_html('http://cwheel.domain.com/');

##### <font size="3" color="blue">Certified Genuine</font>
$element = $html->find("font[size=3][color=blue]", 0);  
echo $element-> plaintext . '<br>';
$html->clear();

?>
4

1 に答える 1

1

I dont know Simple_html_dom. But it seems the query you are trying to pass is an xpath query. In that case you need to use prefix attributes with @. Also you need to prefix the whole query with // to make sure it searches for any font tag that is in any level deep. Final query should look something like this.

//font[@size=3][@color=blue]

Using DOMDocument and DOMXPath it works pretty good.

$doc = new DOMDocument();
$doc->loadHTML($html);
$xpath = new DOMXPath($doc);
$fonts = $xpath->query('font[@size="3" ][ @color="blue"]');
foreach($fonts as $font){
    echo $font->textContent. "\n";
}
于 2013-01-17T06:10:45.387 に答える