Advertisement
AMONRA75

PHP - CURL SCRAPE

Sep 18th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.67 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4.  
  5.  
  6. $domain = "https://www.betfair.it/exchange/cashout";
  7. $ch = curl_init($domain);
  8. //curl_setopt($ch ,CURLOPT_RETURNTRANSFER, true);
  9.  curl_setopt($ch, CURLOPT_URL, $domain);    // Setting cURL's URL option with the $url variable passed into the function
  10.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // Setting cURL's option to return the webpage data
  11.     //curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
  12.     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
  13.     $response = curl_exec($ch); // Executing the cURL request and assigning the returned data to the $data variable
  14.     curl_close($ch);    // Closing cURL
  15. //$response  = curl_exec($ch);
  16.  
  17.  
  18. preg_match_all("/<span class=\"in-play-icon inplay\">(.*?)</", $response, $matchedinplay);
  19. preg_match_all("/<span class=\"home-team\">(.*?)</", $response, $matchedhome);
  20. preg_match_all("/<span class=\"away-team\">(.*?)</", $response, $matchedaway);
  21. preg_match_all("/<span class=\"result\">(.*?)</", $response, $matchedresult);
  22. preg_match_all("/<div class=\"start-time\">(.*?)</", $response, $matchedtime);
  23.  
  24.  
  25.  
  26. //print_r($matchedinplay);
  27.  
  28. $fp = fopen('results.json', 'w');
  29.  
  30. for ($i = 0; $i < count($matchedinplay[1]); $i++) {
  31.  
  32.  
  33.  
  34.  
  35. $trans = array("'" => "", "1º Tempo" => "45");
  36. $rtime = strtr($matchedtime[1][$i],$trans);
  37.  
  38.  
  39.  
  40. $time = str_replace("'","",$matchedtime[1][$i]).str_replace("45","1º Tempo",$matchedtime[1][$i]);
  41.  
  42.  
  43. $def = "80";
  44.  
  45. if($time >= $def){
  46.  
  47.   $isok = "OK";
  48. }else{
  49. $isok = "NO";
  50. }
  51.  
  52. echo "#".$i." ".$matchedhome[1][$i]." - ".$matchedaway[1][$i]." - ".$matchedresult[1][$i]." - ".$rtime." ".$isok."\r\n";
  53.  
  54. fwrite($fp, json_encode($matchedhome[1][$i]));
  55.  
  56.  
  57.  }
  58.  
  59.  
  60.  
  61.  
  62. fclose($fp);
  63.  
  64.  
  65. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement