Web Scraping PHP

Asked

Viewed 30 times

-1

I am making a Web Scraping in PHP to get the auction lot information from this site https://www.sold.com.br/ I need to capture the information in an Array. But the array is not bringing the information in the order I want. He’s bringing in all the dates, then all the assets, the types and the descriptions. I need it to group in the DATA, WELL, TYPE and DESCRIPTION array in the same index, only to then go to the next index of the array.

<?php

require_once "simple_html_dom.php";

  $url = 'https://www.sold.com.br/';
  $hold = array();
  $html = file_get_html($url);
  $i = 0;

  if(!empty($html)) {
   $element = $data = "";

  foreach ($html->find(".container-fluid") as $element) {

      foreach($element -> find(".data")as $data){
        $hold[]["Data"] = trim($data->plaintext); 
      }

      foreach($element -> find(".leilao-tipo-bem")as $tipoBem){
        $hold[]["Bem"] = trim($tipoBem->plaintext); 
      }
      foreach($element -> find(".tipo")as $tipo){      
        $hold[]["Tipo"] = trim($tipo->plaintext);
      }

      foreach($element -> find(".leilao-descricao")as $descricao){      
        $hold[]["Descricao"] = trim($descricao->plaintext);
      }
  $i++;
  } 

}
  print_r($hold);

?>

1 answer

0

I managed to solve!!!

I tweaked some details in the code and changed the class name in the first

<?php

require_once "simple_html_dom.php";

  $url = 'https://www.sold.com.br/';
  $html = file_get_html($url);
  $hold = array();
  if(!empty($html)) {
   //$element = $data = "";
   $i = 0;

  foreach ($html->find(".bloco-leilao") as $element) {
    

      foreach($element -> find(".data")as $data){
        $hold[$i]["Data"] = trim($data->plaintext); 
        
        }
      foreach($element -> find(".leilao-tipo-bem")as $tipoBem){
        $hold[$i]["Bem"] = trim($tipoBem->plaintext);
       
        }
      foreach($element -> find(".tipo")as $tipo){      
        $hold[$i]["Tipo"] = trim($tipo->plaintext);
        
        }
      foreach($element -> find(".leilao-descricao")as $descricao){      
        $hold[$i]["Descricao"] = trim($descricao->plaintext);
        
        }
        $i++;
        }
 
  
}

  print_r($hold); exit;

?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.