fork download
  1. <?php
  2. header('Content-Type: application/json; charset=utf-8');
  3. header('Access-Control-Allow-Origin: *');
  4.  
  5. $url = 'https://f...content-available-to-author-only...t.com/borsa/hisseler/';
  6.  
  7. // cURL ile veri çekme
  8. $ch = curl_init();
  9. curl_setopt($ch, CURLOPT_URL, $url);
  10. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  11. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  12. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36');
  13. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  14. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  15.  
  16. $html = curl_exec($ch);
  17. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  18.  
  19. if($httpCode != 200 || !$html) {
  20. echo json_encode([
  21. 'success' => false,
  22. 'message' => 'Sayfa yüklenemedi',
  23. 'http_code' => $httpCode
  24. ], JSON_UNESCAPED_UNICODE);
  25. }
  26.  
  27. // DOMDocument ile HTML parse etme
  28. $dom = new DOMDocument();
  29. $dom->loadHTML($html);
  30.  
  31. $xpath = new DOMXPath($dom);
  32.  
  33. // Tabloya özel class ile arama
  34. $tables = $xpath->query("//table[contains(@class, 'scrollable') and contains(@class, 'search-table')]");
  35.  
  36. if($tables->length == 0) {
  37. echo json_encode([
  38. 'success' => false,
  39. 'message' => 'Tablo bulunamadı'
  40. ], JSON_UNESCAPED_UNICODE);
  41. }
  42.  
  43. $table = $tables->item(0);
  44. $rows = $xpath->query(".//tr", $table);
  45.  
  46. $data = [];
  47. $headers = [];
  48.  
  49. foreach($rows as $index => $row) {
  50. $cells = $xpath->query(".//td | .//th", $row);
  51. $rowData = [];
  52.  
  53. foreach($cells as $cell) {
  54. $rowData[] = trim($cell->textContent);
  55. }
  56.  
  57. if($index == 0) {
  58. // İlk satır başlıklar
  59. $headers = $rowData;
  60. } else {
  61. // Veri satırları
  62. if(count($rowData) > 0) {
  63. $data[] = $rowData;
  64. }
  65. }
  66. }
  67.  
  68. 'success' => true,
  69. 'headers' => $headers,
  70. 'data' => $data,
  71. 'total_rows' => count($data)
  72. ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  73. ?>
Success #stdin #stdout 0.04s 26356KB
stdin
Standard input is empty
stdout
{"success":false,"message":"Sayfa yüklenemedi","http_code":0}