0

Inside the source code of the url I want to scrape I can see this:

<div class="price">
22.96€
</div>

And this is the php file that I created but it´s not returning any value:

<?php
  $data_scraped = file_get_contents('https://www.example.com/es/busquedas/?type%5B%5D=steam&query=motogp+20');
  $the_start = explode('<div class="price">',$data_scraped);
  
  $the_end = explode('</div>',$the_start[1]);
  
  echo $the_end[0];
?>

Any help would be really appreciated

j08691
  • 204,283
  • 31
  • 260
  • 272

1 Answers1

1

Your question looks similar to this one which makes use of simple_html_dom for web scraping in PHP.

Restructuring your code for usage with simple_html_dom:

<?php
require 'simple_html_dom.php';

$html = file_get_html('https://www.example.com/es/busquedas/?type%5B%5D=steam&query=motogp+20');
$price = $html->find('div[class=price]');

echo $price->plaintext."<br>";
?>