php - Avoid the header of box xpath and curl -


iam writting code web data xpath , curl.

these code ul li contain , worked.

but dont want header..

i write following code avoid header can't

if($row->item(0)->tagname != '<ul class="graybg"><li>مدل خودرو</li>  <li>مشخصات</li><li>قیمت نمایندگی</li><li>قیمت بازار آزاد</li></ul>') 

full code.

$ch = curl_init ("http://www.pedal.ir/price/"); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch,curlopt_useragent,'mozilla/5.0 (windows; u; windows nt 5.1;      en-us; rv:1.8.1.13) gecko/20080311 firefox/2.0.0.13');  curl_setopt($ch, curlopt_header, 0); curl_setopt($ch, curlopt_encoding, 'utf-8');  $page = curl_exec($ch);   $dom = new domdocument('1.0', 'utf-8'); libxml_use_internal_errors(true); $dom->loadhtml($page); libxml_clear_errors(); $xpath = new domxpath($dom);  $data = array(); $table_rows = $xpath-   >query('/html/body/div/div[1]/div/div/div/div/div/div/div[2]/ul '); // target   row (the browser rendered <tbody>, doesnt have one)   if($table_rows->length <= 0) { // exit if not found echo 'no table rows found'; exit;  }   foreach($table_rows $tr) { // foreach row    $row = $tr->childnodes;   if($row->item(0)->tagname != '<ul class="graybg"><li>مدل خودرو</li>  <li>مشخصات</li><li>قیمت نمایندگی</li><li>قیمت بازار آزاد</li></ul>') { //  avoid headers        $data[] = array(          'moled' =>trim($row->item(0)->nodevalue),          'detail' => trim($row->item(2)->nodevalue),             'pricenama' => trim($row->item(4)->nodevalue),             'pricebaza' => trim($row->item(6)->nodevalue),     );   }   }    echo '<pre>';   print_r($data);; 

as alternative, since header has distinct class identifies it, include inside checking:

foreach($table_rows $tr) { // foreach row     $row = $tr->childnodes;      if($row->item(0)->parentnode->getattribute('class') !== 'graybg') { //  avoid headers         $data[] = array(             'moled' =>trim($row->item(0)->nodevalue),             'detail' => trim($row->item(2)->nodevalue),             'pricenama' => trim($row->item(4)->nodevalue),             'pricebaza' => trim($row->item(6)->nodevalue),         );     } } 

sample output


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -