Find div with class using PHP Simple HTML DOM Parser

前端 未结 3 1309
既然无缘
既然无缘 2020-12-15 01:54

I am just starting with the mentioned Parser and somehow running on problems directly with the beginning.

Referring to this tutorial:

http://net.tutsplus.com

相关标签:
3条回答
  • 2020-12-15 02:13

    The right code to get a div with class is:

    $ret = $html->find('div.foo');
    //OR
    $ret = $html->find('div[class=foo]');
    

    Basically you can get elements as you were using a CSS selector.

    source: http://simplehtmldom.sourceforge.net/manual.htm
    How to find HTML elements? section, tab Advanced

    0 讨论(0)
  • 2020-12-15 02:24

    The to find the following elements: DIV -> class(product-inner clearfix) -> class(price) the following XPath can be used:

    foreach($html->find('div[class=product-inner  clearfix]') as $element){
            $itemPrice = $element->find('.price',0)->plaintext;
            echo $itemPrice;
        }
    
    0 讨论(0)
  • 2020-12-15 02:31
    $html = new simple_html_dom();   
    $html->load($output); 
    $items = $html->find('div.youclassname',0)->children(1)->outertext; 
    print_r($items);
    
    0 讨论(0)
提交回复
热议问题