fork download
  1. <?php
  2. header('Access-Control-Allow-Origin: *');
  3. header('Access-Control-Allow-Methods: POST, GET');
  4. header('Access-Control-Allow-Headers: Content-Type');
  5. header('Content-Type: application/json');
  6.  
  7. // First check if cURL is installed
  8. if (!function_exists('curl_init')) {
  9. die(json_encode(['error' => 'cURL is not installed on this server']));
  10. }
  11.  
  12. // Initialize cURL session
  13. $ch = curl_init();
  14.  
  15. // URL to scrape
  16. $url = "https://s...content-available-to-author-only...n.pk/";
  17.  
  18. // Set cURL options
  19. CURLOPT_URL => $url,
  20. CURLOPT_RETURNTRANSFER => true,
  21. CURLOPT_FOLLOWLOCATION => true,
  22. CURLOPT_SSL_VERIFYPEER => false,
  23. CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
  24. ]);
  25.  
  26. // Execute cURL session
  27. $html_content = curl_exec($ch);
  28.  
  29. if (curl_errno($ch)) {
  30. die(json_encode(['error' => curl_error($ch)]));
  31. }
  32.  
  33.  
  34. // Process the content
  35. $dom = new DOMDocument();
  36. $dom->loadHTML($html_content);
  37.  
  38. $xpath = new DOMXPath($dom);
  39.  
  40. // Extract data
  41. $items = [];
  42. $headings = $xpath->query('//h2');
  43.  
  44. if ($headings) {
  45. foreach ($headings as $heading) {
  46. $items[] = [
  47. 'Brand' => trim($heading->textContent),
  48. 'Price' => 'N/A' // You can adjust this based on your needs
  49. ];
  50. }
  51. }
  52.  
  53. echo json_encode($items);
  54. ?>
  55.  
Success #stdin #stdout 0.03s 26412KB
stdin
Standard input is empty
stdout
{"error":"Could not resolve host: solarpanelpriceinpakistan.pk"}