v2.5.2
Giriş yap

Başka siteden veri çekme kodu

genco10
2,333 defa görüntülendi ve 1 kişi tarafından değerlendirildi

Merhabalar Maç tahminlerini paylaşan sitelerden veri çekmek istiyorum
bunu interneten bulduğum basit bir kod ile yapıyordum ama
tabloyu komple çekeyirdum bazı sitelerde ise olmuyordu
ben bu siteden çekmek istiyorum ama yerleri farklı olacak nasıl bir kod ile çekebilirim tahminleri

çekmek istedğim tahminler
bu sitede

Kulandığım kod

 <?php


function siteConnect($site)

{

$ch = curl_init();

$hc = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36 OPR/73.0.3856.415";

curl_setopt($ch, CURLOPT_REFERER, 'http://www.google.com');

curl_setopt($ch, CURLOPT_URL, $site);

curl_setopt($ch, CURLOPT_USERAGENT, $hc);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$site = curl_exec($ch);

curl_close($ch);

// Veriyi parçalama işlemi

preg_match_all('@---(.*?)</div>@si',$site,$veri_derece1);


echo $veri_derece1[0][0];


}

$giris = siteConnect('site adresi');
 

echo $giris;

?>
Cevap yaz
Cevaplar (5)
enverhamurhan
423 gün önce

Merhabalar hocam,
Bir başka bir siteden şöyle https://..../12.png bir linkteki dosya var mı yok mu naıl anlarım.
dosyayı dowload ettiğimde resim yoksa da (13.png yok diyelim) 1 kb değerinde boş bir resim çekiliyor.
Bunu nasıl engellerim.

genco10
792 gün önce

Merhaba hocam verileri sorunsuz bir şekilde çektim ama ben verileri tabloya yazamak istediğimde verileri tabloya eklerken tabloda veriler boş görünüyor
kodların tamamı bu şekilde nasıl verileri tabloya ekleyebilirim normalde html olarak çektiğimde olduyor bazı web siteler ama bu curl olduğu için
tabloya yazılmıyor

    <?php 
include_once 'simple_html_dom.php';
$dom = new simple_html_dom();

$ch= curl_init('https://www.mybets.today/soccer-predictions/');
curl_setopt_array($ch, [
   CURLOPT_RETURNTRANSFER => true,
   CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36 OPR/73.0.3856.415'
]);

$result = curl_exec($ch);
curl_close($ch);


$dom->load($result);

$c = $dom->find('.event-fixtures');
$data = [];

foreach ($c as $item) {
    $lig = $item->find("meta[itemprop='name address']")[0]->content;
    $tarih = $item->find("time")[0]->datetime;
    $saat = $item->find("time")[0]->plaintext;
    $takim1 = $item->find("span.homespan")[0]->plaintext;
    $takim2 = $item->find("span.awayspan")[0]->plaintext;
    $oran = $item->find(".tipdiv > span")[0]->plaintext;
    $data[$lig][] = [
        'tarih' => $tarih,
        'saat' => $saat,
        'takim_1' => $takim1,
        'takim_2' => $takim2,
        'oran' => $oran
    ];
}

print_r($data);
 ?>


 <!DOCTYPE html>
 <html>
 <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>BOT YAPIMI</title>
        <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>

 </head>
 <body>
  <div class="container">
       <div class="table-content">
 <table class="table table-striped">
  <thead>
    <tr>
      <th scope="col">#</th>
      <th scope="col">First</th>
      <th scope="col">Last</th>
      <th scope="col">Handle</th>
    </tr>
  </thead>
  <tbody> 
     <?php foreach ($c as $ch => $item): ?>
            
           
    
    <tr>
      <th scope="row"><?php  $tarih = $item->find("time")[0]->datetime; ?></th>
      <td> <?php $takim1 = $item->find("span.homespan")[0]->plaintext;?></td>
      <td><?php $takim2 = $item->find("span.awayspan")[0]->plaintext; ?></td>
      <td>@mdo</td>
    </tr>
          <?php endforeach ?>            

  </tbody>
</table>
 </body>
 </html>
abdullahx
798 gün önce

Öyle pat diye çalışmaz, dosya yollarını falan kendine göre düzenlemen lazım. Ortaya çıkan datayı işlemen lazım

genco10
798 gün önce

Hocam Bağlantıdaki dosyaları indirdim atım sunucuya başka sayfa oluşturdum gönderdiğiniz kodları ekledim ama çalışmadı

abdullahx
798 gün önce
include_once '../simple_html_dom.php';
$dom = new simple_html_dom();

$ch = curl_init('https://www.mybets.today/soccer-predictions/');
curl_setopt_array($ch, [
   CURLOPT_RETURNTRANSFER => true,
   CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36 OPR/73.0.3856.415'
]);

$result = curl_exec($ch);
curl_close($ch);


$dom->load($result);

$c = $dom->find('.event-fixtures');
$data = [];

foreach ($c as $item) {
    $lig = $item->find("meta[itemprop='name address']")[0]->content;
    $tarih = $item->find("time")[0]->datetime;
    $saat = $item->find("time")[0]->plaintext;
    $takim1 = $item->find("span.homespan")[0]->plaintext;
    $takim2 = $item->find("span.awayspan")[0]->plaintext;
    $oran = $item->find(".tipdiv > span")[0]->plaintext;
    $data[$lig][] = [
        'tarih' => $tarih,
        'saat' => $saat,
        'takim_1' => $takim1,
        'takim_2' => $takim2,
        'oran' => $oran
    ];
}

print_r($data);

simple html dom parser ı [bu] (https://simplehtmldom.sourceforge.io/) adresten indir ve sayfana dahil et. Gerisi sihir