Advertisement
PyNoob1

Step-3-888Sport odds scraper_raw

Jun 11th, 2021
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.48 KB | None | 0 0
  1. import pandas as pd
  2. from soccerapi.api import Api888Sport
  3. from tabulate import tabulate
  4. from ast import literal_eval
  5.  
  6. pd.set_option('display.max_rows', 5000)
  7. pd.set_option('display.max_columns', 500)
  8. pd.set_option('display.width', 1000)
  9.  
  10. api = Api888Sport()
  11. print("Getting English Premier League Odds")
  12. url_epl = 'https://www.888sport.com/#/filter/football/england/premier_league'
  13. odds_epl = api.odds(url_epl)
  14. odds_epl = pd.DataFrame(data=odds_epl)
  15. odds_epl['League'] = 'English Premier League'
  16. print("Getting England Championship Odds")
  17. url_ec1 = 'https://www.888sport.com/#/filter/football/england/the_championship'
  18. odds_ec1 = api.odds(url_ec1)
  19. odds_ec1 = pd.DataFrame(data=odds_ec1)
  20. odds_ec1['League'] = 'England Championship'
  21. print("Getting England League 1 Odds")
  22. url_el1 = 'https://www.888sport.com/#/filter/football/england/league_one/'
  23. odds_el1 = api.odds(url_el1)
  24. odds_el1 = pd.DataFrame(data=odds_el1)
  25. odds_el1['League'] = 'England League 1'
  26. print("Getting England League 2 Odds")
  27. url_el2 = 'https://www.888sport.com/#/filter/football/england/league_two/'
  28. odds_el2 = api.odds(url_el2)
  29. odds_el2 = pd.DataFrame(data=odds_el2)
  30. odds_el2['League'] = 'England League 2'
  31. # print("Getting England National League Odds")
  32. # url_enl = 'https://www.888sport.com/#/filter/football/england/england_national_league/'
  33. # odds_enl = api.odds(url_enl)
  34. # odds_enl = pd.DataFrame(data=odds_enl)
  35. # odds_enl['League'] = 'England National League'
  36. print("Getting Belgium First Division Odds")
  37. url_bfda = 'https://www.888sport.com/#/filter/football/belgium/'
  38. odds_bfda = api.odds(url_bfda)
  39. odds_bfda = pd.DataFrame(data=odds_bfda)
  40. odds_bfda['League'] = 'Belgium First Division'
  41. print("Getting Germany Bundesliga 1 Odds")
  42. url_gb1 = 'https://www.888sport.com/#/filter/football/germany/bundesliga/'
  43. odds_gb1 = api.odds(url_gb1)
  44. odds_gb1 = pd.DataFrame(data=odds_gb1)
  45. odds_gb1['League'] = 'Germany Bundesliga 1'
  46. # print("Getting Germany Bundesliga 2 Odds")
  47. # url_gb2 = 'https://www.888sport.com/#/filter/football/germany/2_bundesliga/'
  48. # odds_gb2 = api.odds(url_gb2)
  49. # odds_gb2 = pd.DataFrame(data=odds_gb2)
  50. # odds_gb2['League'] = 'Germany Bundesliga 2'
  51. print("Getting France League 1 Odds")
  52. url_fl1 = 'https://www.888sport.com/#/filter/football/france/ligue_1/'
  53. odds_fl1 = api.odds(url_fl1)
  54. odds_fl1 = pd.DataFrame(data=odds_fl1)
  55. odds_fl1['League'] = 'France League 1'
  56. print("Getting France League 2 Odds")
  57. url_fl2 = 'https://www.888sport.com/#/filter/football/france/ligue_2/'
  58. odds_fl2 = api.odds(url_fl2)
  59. odds_fl2 = pd.DataFrame(data=odds_fl2)
  60. odds_fl2['League'] = 'France League 2'
  61. # print("Getting Greece Super League 1 Odds")
  62. # url_gsl1 = 'https://www.888sport.com/#/filter/football/greece/greece_super_league/'
  63. # odds_gsl1 = api.odds(url_gsl1)
  64. # odds_gsl1 = pd.DataFrame(data=odds_gsl1)
  65. # odds_gsl1['League'] = 'Greece Super League 1'
  66. print("Getting Italy Serie A Odds")
  67. url_seriea = 'https://www.888sport.com/#/filter/football/italy/serie_a/'
  68. odds_seriea = api.odds(url_seriea)
  69. odds_seriea = pd.DataFrame(data=odds_seriea)
  70. odds_seriea['League'] = 'Italy Serie A'
  71. # print("Getting Italy Serie B Odds")
  72. # url_serieb = 'https://www.888sport.com/#/filter/football/italy/italy_serie_b/'
  73. # odds_serieb = api.odds(url_serieb)
  74. # odds_serieb = pd.DataFrame(data=odds_serieb)
  75. # odds_serieb['League'] = 'Italy Serie B'
  76. print("Getting Netherlands Eredivisie Odds")
  77. url_nerd = 'https://www.888sport.com/#/filter/football/netherlands/eredivisie/'
  78. odds_nerd = api.odds(url_nerd)
  79. odds_nerd = pd.DataFrame(data=odds_nerd)
  80. odds_nerd['League'] = 'Netherlands Eredivisie'
  81. # print("Getting Portugal Primeira Liga Odds")
  82. # url_ppl = 'https://www.888sport.com/#/filter/football_betting/portuguese_super_liga_odds/'
  83. # odds_ppl = api.odds(url_ppl)
  84. # odds_ppl = pd.DataFrame(data=odds_ppl)
  85. # odds_ppl['League'] = 'Portugal Primeira Liga'
  86. # print("Getting Scotland Premiership Odds")
  87. # url_spr = 'https://www.888sport.com/#/filter/football/scotland/scotland_premiership/'
  88. # odds_spr = api.odds(url_spr)
  89. # odds_spr = pd.DataFrame(data=odds_spr)
  90. # odds_spr['League'] = 'Scotland Premiership'
  91. print("Getting Spain La Liga Odds")
  92. url_spl = 'https://www.888sport.com/#/filter/football/spain/la_liga/'
  93. odds_spl = api.odds(url_spl)
  94. odds_spl = pd.DataFrame(data=odds_spl)
  95. odds_spl['League'] = 'Spain Primera Liga'
  96. # print("Getting Spain Segunda Odds")
  97. # url_sp2 = 'https://www.888sport.com/#/filter/football/spain/spain_segunda_division/'
  98. # odds_sp2 = api.odds(url_sp2)
  99. # odds_sp2 = pd.DataFrame(data=odds_sp2)
  100. # odds_sp2['League'] = 'Spain Segunda'
  101. # print("Getting Turkey Super Lig Odds")
  102. # url_tsl = 'https://www.888sport.com/#/filter/football/turkey/turkey_super_lig/'
  103. # odds_tsl = api.odds(url_tsl)
  104. # odds_tsl = pd.DataFrame(data=odds_tsl)
  105. # odds_tsl['League'] = 'Turkey Super Lig'
  106.  
  107. odds_list = [
  108.     odds_epl,
  109.     odds_ec1,
  110.     odds_el1,
  111.     odds_el2,
  112.     # odds_enl,
  113.     odds_bfda,
  114.     odds_gb1,
  115.     # odds_gb2,
  116.     odds_fl1,
  117.     odds_fl2,
  118.     # odds_gsl1,
  119.     odds_seriea,
  120.     # odds_serieb,
  121.     odds_nerd,
  122.     # odds_ppl,
  123.     # odds_spr,
  124.     odds_spl,
  125.     # odds_sp2,
  126.     # odds_tsl
  127. ]
  128.  
  129. df = pd.concat(odds_list)
  130.  
  131. df = df.dropna()
  132.  
  133. df.drop(list(df.filter(regex='None')), axis=1, inplace=True)
  134.  
  135. print("Rearranging columns")
  136.  
  137. df = df[['time', 'League', 'home_team', 'away_team', 'full_time_result', 'both_teams_to_score', 'double_chance']]
  138. print(tabulate(df, headers='keys'))
  139.  
  140. df.to_csv(r"C:\Users\harsh\Google Drive\sportsintel.shop\Files\Output\odds_raw.csv")
  141.  
  142. print("888Sport Data downloaded successfully")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement