Advertisement
Guest User

Untitled

a guest
Feb 25th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. <?php
  2.  
  3. //nba spider
  4.  
  5. require 'simple_html_dom.php';
  6.  
  7. //Upload a blank cookie.txt to the same directory as this file with a CHMOD/Permission to 777
  8. function login($url,$data){
  9. $fp = fopen("cookie.txt", "w");
  10. fclose($fp);
  11. $login = curl_init();
  12. curl_setopt($login, CURLOPT_COOKIEJAR, "cookie.txt");
  13. curl_setopt($login, CURLOPT_COOKIEFILE, "cookie.txt");
  14. curl_setopt($login, CURLOPT_TIMEOUT, 40000);
  15. curl_setopt($login, CURLOPT_RETURNTRANSFER, TRUE);
  16. curl_setopt($login, CURLOPT_URL, $url);
  17. curl_setopt($login, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
  18. curl_setopt($login, CURLOPT_FOLLOWLOCATION, TRUE);
  19. curl_setopt($login, CURLOPT_POST, TRUE);
  20. curl_setopt($login, CURLOPT_POSTFIELDS, $data);
  21. ob_start();
  22. return curl_exec ($login);
  23. ob_end_clean();
  24. curl_close ($login);
  25. unset($login);
  26. }
  27.  
  28. function grab_page($site){
  29. $ch = curl_init();
  30. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  31. curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
  32. curl_setopt($ch, CURLOPT_TIMEOUT, 40);
  33. curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
  34. curl_setopt($ch, CURLOPT_URL, $site);
  35. ob_start();
  36. return curl_exec ($ch);
  37. ob_end_clean();
  38. curl_close ($ch);
  39. }
  40.  
  41. function post_data($site,$data){
  42. $datapost = curl_init();
  43. $headers = array("Expect:");
  44.  
  45. curl_setopt($datapost, CURLOPT_URL, $site);
  46. curl_setopt($datapost, CURLOPT_TIMEOUT, 40000);
  47. curl_setopt($datapost, CURLOPT_HEADER, TRUE);
  48. curl_setopt($datapost, CURLOPT_HTTPHEADER, $headers);
  49. curl_setopt($datapost, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
  50. curl_setopt($datapost, CURLOPT_POST, TRUE);
  51. curl_setopt($datapost, CURLOPT_POSTFIELDS, $data);
  52. curl_setopt($datapost, CURLOPT_RETURNTRANSFER, 1); // return the output in string format
  53. curl_setopt($datapost, CURLOPT_COOKIEFILE, "cookie.txt");
  54. ob_start();
  55. return curl_exec ($datapost);
  56. ob_end_clean();
  57. curl_close ($datapost);
  58. unset($datapost);
  59. }
  60.  
  61.  
  62.  
  63.  
  64. $servername = "";
  65. $username = "";
  66. $password = "";
  67. $dbname = "";
  68.  
  69. // Create connection
  70. $conn = mysqli_connect($servername, $username, $password, $dbname);
  71.  
  72. // Check connection
  73. if (!$conn) {
  74. die("Connection failed: " . mysqli_connect_error());
  75. }
  76. //echo "Connected successfully";
  77.  
  78.  
  79. foreach ($html->find('.teams_betting_options_advance') as $table)
  80. {
  81. //echo $table->innertext.'<br>';
  82. //$date = $table->find('.opt_advance_date');
  83. //echo $date.'<br>';
  84.  
  85. // game date and time
  86. $date = $table->find('.opt_advance_date', 0)->innertext;
  87.  
  88. //top line
  89. $team_top = $table->find('span[data-language]', 0)->innertext;
  90. $team_top_spread = $table->find('option[selected]', 0)->innertext;
  91. $team_top_spread =substr($team_top_spread, 0, -10);
  92. $team_top_money_line = substr($table->find('.tbl_betAmount_td', 1)->innertext, -4);
  93. $both_over = substr($table->find('option[selected]', 1)->innertext, 1, -10);
  94.  
  95. //bottom line
  96. $team_bottom = $table->find('span[data-language]', 1)->innertext;
  97. $team_bottom = trim($team_bottom);
  98. $team_bottom_spread = $table->find('option[selected]', 2)->innertext;
  99. $team_bottom_spread =substr($team_bottom_spread, 0, -10);
  100. $team_bottom_money_line = substr($table->find('.tbl_betAmount_td', 6)->innertext, -4);
  101. $both_under = substr($table->find('option[selected]', 3)->innertext, 1, -10);
  102.  
  103.  
  104. //date time to mysql format
  105. $date = preg_replace("/&#?[a-z0-9]+;/i"," ",$date);
  106. $date = date('Y-m-d H:i:s', strtotime(str_replace('-', '/', $date)));
  107.  
  108.  
  109.  
  110.  
  111.  
  112. //insert each into database
  113. $sql = 'INSERT INTO ncaa (date_time, team_top, team_top_spread, team_top_money_line, both_over, team_bottom, team_bottom_spread, team_bottom_money_line, both_under)
  114. VALUES ("'.$date.'", "'.$team_top.'", "'.$team_top_spread.'", "'.$team_top_money_line.'", "'.$both_over.'", "'.$team_bottom.'", "'.$team_bottom_spread.'", "'.$team_bottom_money_line.'", "'.$both_under.'")';
  115.  
  116. if ($conn->query($sql) === TRUE) {
  117. echo "New record created successfully";
  118. } else {
  119. echo "Error: " . $sql . "<br>" . $conn->error;
  120. }
  121.  
  122.  
  123.  
  124. }
  125.  
  126. $conn->close();
  127. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement