Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include('../simple_html_dom.php');
- function getHTML($url,$timeout)
- {
- $ch = curl_init($url); // initialize curl with given url
- curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); // set useragent
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // write the response to a variable
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirects if any
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // max. seconds to execute
- curl_setopt($ch, CURLOPT_FAILONERROR, 1); // stop when it encounters an error
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- return @curl_exec($ch);
- }
- $response=getHTML("http://www.betexplorer.com/soccer/england/premier-league/results/",10);
- $html = str_get_html($response);
- $titles = $html->find("a[class=in-match]"); // 1 per match
- $result = $html->find("td[class=h-text-center]/a"); // 1
- $best_bets = $html->find("td[class=table-matches__odds colored]/span/span/span"); // 1
- $odds = $html->find("td[class=table-matches__odds]"); // 2
- function print_odd($odd) {
- if (array_key_exists('data-odd', $odd->attr)) {
- return $odd->attr['data-odd'];
- }
- return $odd->children(0)->children(0)->children(0)->attr['data-odd'];
- }
- $c=0; $b=0; $o=0; $z=0; // two counters
- foreach ($titles as $match) {
- list($num1, $num2) = explode(':', $result[$c++]->innertext); // <- explode
- $num1 = intval($num1);
- $num2 = intval($num2);
- $num3 = ($num1 + $num2);
- if ($num3 > 1) {
- $over15 = "OK";
- } else {
- $over15 = "NO";
- }
- echo "<tr><td class='rtitle'>".
- "<td class='first-cell'>".$match->innertext."</td> ".
- "<td>".$match->innertext."</td><td> ".$num1.'</td><td> : </td><td>'.$num2 . " / " . // <- example use
- "<td class='first-cell'>".$num3 ."</td> " .
- "<td class='first-cell'>".$over15 ."</td> " .
- "<td class='odds'>".print_odd($odds[$b++]) . ";" .
- "".print_odd($odds[$b++]) . ";" .
- "".print_odd($odds[$b++]) . "</td>" .
- "</td></tr><br/>";
- $servername = "xx.xxx.xxx.xxx";
- $username = "xxx";
- $password = "xxx";
- $dbname = "xxxxxxxx";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $sql = "INSERT INTO risultati (titles, scorehome, scoreaway, best_bets)
- VALUES ('$match', '$num1', '$num2', '$odds');";
- if ($conn->multi_query($sql) === TRUE) {
- echo "New records created successfully";
- } else {
- echo "Error: " . $sql . "<br>" . $conn->error;
- }
- $conn->close();
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement