Suneth Kalhara
Suneth Kalhara

Reputation: 1208

simple_html_dom access ul inside div

I'm using simple_html_dom for class html grabbing script, i got a problem when trying to grab ul inside a div

HTML

<div class="attributes">
      <div class="headline">test header</div>
                <ul>
                  <li>test 1</li>
                  <li>test 2</li>
                  <li>test 3</li>

                </ul>
    </div>

PHP

//call to function
$url = 'http://example.com';

$data = dlPage2($url,'.attributes');
echo $data;


//function

function dlPage2($href,$element) {

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curl, CURLOPT_URL, $href);
    curl_setopt($curl, CURLOPT_REFERER, $href);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.125 Safari/533.4");
    $str = curl_exec($curl);
    curl_close($curl);

    // Create a DOM object
    $dom = new simple_html_dom();
    // Load HTML from a string
    $dom->load($str);
$dom= $dom->find($element,0)->outertext;
    return $dom;
    }

above code i can grab whole <div class="attributes"> but i need to get html of <ul> tag inside that div,

can someone help me to change this please

Upvotes: 0

Views: 216

Answers (1)

DrKey
DrKey

Reputation: 3495

You have to select <ul> inside $element by using

$dom = $dom->find($element.' ul', 0)->outertext;

Upvotes: 1

Related Questions