Merhaba arkadaşlar aşağıdaki kodu kendinize göre uyarlayarak corona verilerini sayfanıza çekebilirsiniz.
<center><b><?php setlocale(LC_TIME,'turkish'); //turkceyi sec (sunucuda yüklü olması gerekir) echo iconv('latin5','utf-8',strftime('%e %B %Y %A')); //kodun çalıştığı zamana ait //19 Şubat 2020 Çarşamba ?></b></center> <?php error_reporting(0); function curl_connect($url){ // curl bağlantı fonksiyonu $agent = $_SERVER["HTTP_USER_AGENT"]; // Buraya istersek kendimiz de tarayıcı bilgisi girebiliriz. (Ör. Android, İos, Ipad vs.) $curl = curl_init(); // Curl oturumu başlat curl_setopt($curl, CURLOPT_URL, $url); // url'ye bağlan curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Veriyi ekrana yazma. Değişkene aktarıp ayıklayacağım curl_setopt($curl, CURLOPT_USERAGENT, $agent); // Siteye tarayıcı bilgisi gönder, uyanmasın. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // SSL kontrolünü iptal ettik. Bu sayede site botumuzu engelleyemez. $content = curl_exec($curl); // Curl oturumunu çalıştır ve gelen sonucu değişkene aktar. curl_close($curl); // İşimiz bitti, oturumu sonlandır. $content = preg_replace("/\s+/", " ", $content); // boşlukları temizle $content = preg_replace("/\r|\n/", " ", $content); // yeni satırları temizle $content = preg_replace("/\t+/", "", $content); // tabları temizle $content = preg_replace("/<script\b[^>]*>(.*?)<\/script>/is", "", $content); // javascript kodlarını temizle $content = trim($content); // başta ve sonda kalan boşlukları temizle return $content; // Sonuç döndür } function curl_search($first, $last, $content){ // $content parametresi içinde, $first ve $last parametreleri ile gelen değerler arasındaki veriyi bulup sonuç döndürür. @preg_match_all('/' . preg_quote($first, '/').'(.*?)'. preg_quote($last, '/').'/i', $content, $m); return @$m[1]; } $site_adresimiz = curl_connect("https://projects.nodetent.com/coronatracker/"); $getir = curl_search('<div id="main">', '<footer>', $site_adresimiz); $getir = preg_replace('/<a href=\"(.*?)\">(.*?)<\/a>/', "\2", $getir); // html temizle $getir = preg_replace('#<div class="card">(.*?)<div class="card">#', ' ', $getir); // div sil $getir = preg_replace('#<div class="card-body">(.*?)<div class="card">#', ' ', $getir); // div sil $getir=preg_replace("/Total Cases[^ ]+/i","Toplam Vaka",$getir); // kelime değiştir $getir=preg_replace("/Total Deaths[^ ]+/i","Toplam Ölüm",$getir); $getir=preg_replace("/Total Recovered[^ ]+/i","Toplam İyileşen",$getir); $getir=preg_replace("/New Cases Today[^ ]+/i","Bugünki Vakalar",$getir); $getir=preg_replace("/New Deaths Today[^ ]+/i","Bugün Ölenler",$getir); $getir=preg_replace("/Critical Cases[^ ]+/i","Kritik Vakalar",$getir); $getir=preg_replace("/Location[^ ]+/i","Ülke",$getir); $getir=preg_replace("/Confirmed Cases[^ ]+/i","Vaka Sayısı",$getir); $getir=preg_replace("/Active Cases[^ ]+/i","Aktif Vakalar",$getir); $getir=preg_replace("/Deaths[^ ]+/i","Ölümler",$getir); $getir=preg_replace("/Recovered[^ ]+/i","İyileşen",$getir); $getir=preg_replace("/Mortality Rate[^ ]+/i","Ölüm Oranı (%)",$getir); $getir=preg_replace("/Recovery Rate[^ ]+/i","İyileşme Oranı (%)",$getir); $getir=preg_replace("/Total Tests[^ ]+/i","Toplam Test",$getir); for($sayi = 0; $sayi < 19; $sayi++) { echo $getir[$sayi]; } ?> </div> <!-- end::main-content --> </div> <!-- end::main --> <!-- scripts --> <script src="assets/js/jquery.min.js"></script> <script src="assets/js/bootstrap.min.js"></script> <script src="assets/js/app.min.js"></script> <script src="assets/js/jquery.dataTables.js"></script> <script src="assets/js/dataTables.bootstrap4.min.js"></script> <script src="assets/js/dataTables.responsive.min.js"></script> <script src="assets/js/responsive.bootstrap4.min.js"></script> <script> $(document).ready(function () { $('table').DataTable({ order: [], paging: true, "pageLength": 25, "pagingType": "simple", "dom": '<"top"flp>rt<"bottom"ip><"clear">', }); console.clear(); }); </script>
Yorumlar