[ 'url' => [ 'name' => 'URL de la page de recherche', 'type' => 'text', 'required' => true, 'title' => 'URL d\'une recherche avec filtre de véhicules sans le http://www.autojm.fr/', 'exampleValue' => 'recherche?brands[]=peugeot&ranges[]=peugeot-nouvelle-308-2021-5p' ], ] ]; const CACHE_TIMEOUT = 3600; public function getIcon() { return self::URI . 'favicon.ico'; } public function getName() { switch ($this->queriedContext) { case 'Afficher les offres de véhicules disponible sur la recheche AutoJM': return 'AutoJM | Recherche de véhicules'; break; default: return parent::getName(); } } public function collectData() { // Get the number of result for this search $search_url = self::URI . $this->getInput('url') . '&open=energy&onlyFilters=false'; // Set the header 'X-Requested-With' like the website does it $header = [ 'X-Requested-With: XMLHttpRequest' ]; // Get the JSON content of the form $json = getContents($search_url, $header); // Extract the HTML content from the JSON result $data = json_decode($json); $nb_results = $data->nbResults; $total_pages = ceil($nb_results / 15); // Limit the number of page to analyse to 10 for ($page = 1; $page <= $total_pages && $page <= 10; $page++) { // Get the result the next page $html = $this->getResults($page); // Go through every car of the search $list = $html->find('div[class*=card-car card-car--listing]'); foreach ($list as $car) { // Get the info about the car offer $image = $car->find('div[class=card-car__header__img]', 0)->find('img', 0)->src; // Decode HTML attribute JSON data $car_data = json_decode(html_entity_decode($car->{'data-layer'})); $car_model = $car->{'data-title'} . ' ' . $car->{'data-suptitle'}; $availability = $car->find('div[class=card-car__modalites]', 0)->find('div[class=col]', 0)->plaintext; $warranty = $car->find('div[data-type=WarrantyCard]', 0)->plaintext; $discount_html = $car->find('div[class=subtext vehicle_reference_element]', 0); // Check if there is any discount info displayed if ($discount_html != null) { $reference_price_value = $discount_html->find('span[data-cfg=vehicle__reference_price]', 0)->plaintext; $discount_percent_value = $discount_html->find('span[data-cfg=vehicle__discount_percent]', 0)->plaintext; $reference_price = '
' . $car_model . '
'; $item['content'] .= '