format('Y-m-d H:i:s'); // Kripto para kurları $response = $this->fetchData('https://www.doviz.com/kripto-paralar'); // DOM işlemleri için veri çekme $dom = new \DOMDocument(); @$dom->loadHTML($response->body()); $xpath = new \DOMXPath($dom); // Kripto para verilerini içeren tabloyu ID'ye göre bul $rows = $xpath->query("//table[@id='coins']/tbody/tr"); foreach ($rows as $row) { $symbol = trim($xpath->evaluate("string(.//td[1]//text()[last()])", $row)); // Semboldeki boşlukları temizle ve sadece kripto para sembolünü al $symbol = preg_replace('/^.*\s(\w+)\s*$/', '$1', $symbol); // Kripto para ismini al $name = $xpath->evaluate("string(.//td[1]//div[@class='cname'])", $row); if (strlen($symbol) > 0) { $priceUSD = $xpath->evaluate("string(.//td[2])", $row); $priceTRY = $xpath->evaluate("string(.//td[3])", $row); $change = $xpath->evaluate("string(.//td[6])", $row); // Fiyat verilerini temizle (örn: $3.310,57 -> 3310.57) $priceUSD = str_replace('$', '', $priceUSD); $priceUSD = str_replace('.', '', $priceUSD); $priceUSD = str_replace(',', '.', $priceUSD); $priceTRY = str_replace('₺', '', $priceTRY); $priceTRY = str_replace('.', '', $priceTRY); $priceTRY = str_replace(',', '.', $priceTRY); $change = str_replace('%', '', $change); $change = str_replace('.', '', $change); $change = str_replace(',', '.', $change); $data[$symbol] = [ 'Name' => trim($name), 'USD_Price' => (float)$priceUSD, 'TRY_Price' => (float)$priceTRY, 'Selling' => (float)$priceTRY, 'Change' => (float)$change, 'Type' => 'CryptoCurrency' ]; } } // JSON dosyasını kaydet Storage::put('crypto/today.json', json_encode($data, JSON_UNESCAPED_UNICODE)); return $data; } private function fetchData($url) { return Http::withHeaders([ 'User-Agent' => 'Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10', 'Accept-Language' => 'en' ])->get($url); } }