fork download
  1. <?php
  2. // Construct the URL with dealer_id and page number
  3. $dealer_id = "10026796"; // Replace with your dealer ID
  4. $page = 1;
  5. $url = 'https://c...content-available-to-author-only...o.uk/dealer-stock?' .
  6. 'owned=true' .
  7. '&include_relevant_links=true' .
  8. '&start=' . $page .
  9. '&sort_by=year' .
  10. '&sort_order=desc' .
  11. '&dealer_id=' . $dealer_id;
  12.  
  13. // Output the URL for debugging
  14. echo "Fetching URL: " . $url . "<br>";
  15.  
  16. // Initialize cURL session
  17. $ch = curl_init();
  18.  
  19. // Set cURL options
  20. curl_setopt($ch, CURLOPT_URL, $url);
  21. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  22. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Follow redirects
  23. curl_setopt($ch, CURLOPT_FAILONERROR, true); // Return false on HTTP error
  24.  
  25. // Execute the request
  26. $html = curl_exec($ch);
  27.  
  28. // Check for cURL errors
  29. if ($html === false) {
  30. $error_msg = curl_error($ch);
  31. echo "cURL error: " . $error_msg . "<br>";
  32. } else {
  33. // Output the HTML content for debugging
  34. echo "<pre>" . htmlspecialchars($html) . "</pre>";
  35.  
  36. // Extract links matching the pattern
  37. preg_match_all('/https:\/\/cars\.motorsync\.co\.uk\/stock-detail\/\S+/', $html, $matches);
  38.  
  39. // Output the matches for debugging
  40. echo "<h2>Extracted Links:</h2>";
  41. print_r($matches);
  42. }
  43.  
  44. // Close cURL session
  45. ?>
  46.  
Success #stdin #stdout 0.03s 26208KB
stdin
Standard input is empty
stdout
Fetching URL: https://c...content-available-to-author-only...o.uk/dealer-stock?owned=true&include_relevant_links=true&start=1&sort_by=year&sort_order=desc&dealer_id=10026796<br>cURL error: Could not resolve host: cars.motorsync.co.uk<br>