Friday, October 26, 2018

amazon Reprise

foreach($rows as $index => $row){
   $img  = array();
   $innerHTML  = "";
   $SellerName = "";
   $i++;
   if($i%4==0) continue;
   if($i%5==0) {
    $data[] = $op;
    $op = array();
    $i=0;
    continue;
   }
   if($i==1){
    $text = preg_replace('/[^A-Za-z0-9." ]/', " ", $row->textContent);
    $text = preg_replace('/\s+/', ' ', $text);
    $op['price'] = $text;
   }else if($i==2){
    $text = preg_replace('/[^A-Za-z0-9." ]/', " ", $row->textContent);
    $text = preg_replace('/\s+/', ' ', $text);
    $op['condition'] = $text;
   }else if($i==3){
    $children = $row->childNodes;
    foreach ($children as $child)
    {
     $innerHTML .= $child->ownerDocument->saveXML( $child );
    }
    preg_match_all('/(alt|title|src)=("[^"]*")/i',$innerHTML, $img);
 
    if(!empty($img[2][0])){

     $imgTitle    = str_replace('"',"",$img[2][0]);
     $text     = preg_replace('/[^A-Za-z0-9." ]/', " ", $row->textContent);
     $text     = preg_replace('/\s+/', ' ', $text);
     $op['sellerName'] = strtoupper($imgTitle);
     $text     = "<b>".strtoupper($imgTitle) ."</b>"." ". $text;
     $op['seller']   = str_replace(" Just Launched Seller Profile","",$text);

    }else{
   
     $text     = preg_replace('/[^A-Za-z0-9." ]/', " ", $row->textContent);
     $text     = preg_replace('/\s+/', ' ', $text);
     $op['seller']   = str_replace(" Just Launched Seller Profile","",$text);
     $RawData    = explode(" out of ",strip_tags($op['seller']));
     foreach ($RawData as $key => $value){
       $FirrstValue  = $value;
       break;
     }
   
     $RawDataName = explode(" ",$FirrstValue);
     foreach ($RawDataName as $key => $value){
      $pos = strpos($value, ".");
      if ($pos === false) {
       $SellerName .= $value ." ";
      } else {
       break;
      }
     }

     $op['sellerName'] = trim(str_replace("1","",$SellerName));
     $op['seller'] = str_replace($op['sellerName'],"<b>".strtoupper($op['sellerName'])."</b> ",$op['seller']);

    }
   }
  }

No comments:

Post a Comment