How to scrape NHL team names and odds from API?












1














I am hoping for the following info:



1) NHL Team Names



2) Betting Odds



Here is the site: https://www.bovada.lv/services/sports/event/v2/events/A/description/hockey/nhl.



Here is my code so far:



import requests

source = requests.get("https://www.bovada.lv/services/sports/event/v2/events/A/description/hockey/nhl").json()

data = source[0]

for game in data['events'][2].items():
print(game)


The code above only prints the data for one game. I was hoping for all of the games. Is there an easy way to loop through all of them? I am also not sure how to parse out the info I am looking for.




  • Team Names


I noticed the team names are located in the section titled 'competitors':



competitors":[{"id":"3596982-510","name":"Philadelphia Flyers","home":true},{"id":"3596982-376","name":"New York Rangers","home":false}]


In the example above the info I am looking for is Philadelphia Flyers and New York Rangers, respectively.




  • Odds


(Note: the odds change so the numbers you see may be different)



I also noticed the spread with odds is located in the section titled 'display groups':



"displayGroups":[{"id":"100-128","description":"Game Lines","defaultType":true,"alternateType":false,"markets":[{"id":"57349611","description":"Total","key":"2W-OU","marketTypeId":"120743","status":"O","singleOnly":false,"notes":"","period":{"id":"1191","description":"Match","abbreviation":"M","live":false,"main":true},"outcomes":[{"id":"294606239","description":"Over","status":"O","type":"O","price":{"id":"1836755921","handicap":"6.5","american":"EVEN","decimal":"2.00","fractional":"1/1","malay":"1.00","indonesian":"1.00","hongkong":"1.00"}},{"id":"294606240","description":"Under","status":"O","type":"U","price":{"id":"1836755922","handicap":"6.5","american":"-125","decimal":"1.800","fractional":"4/5","malay":"0.80","indonesian":"-1.25","hongkong":"0.80"}}]},{"id":"57349614","description":"Moneyline","key":"2W-12","marketTypeId":"372","status":"O","singleOnly":false,"notes":"","period":{"id":"1191","description":"Match","abbreviation":"M","live":false,"main":true},"outcomes":[{"id":"294606235","description":"New York Rangers","status":"O","type":"A","competitorId":"3596982-376","price":{"id":"1836569815","american":"+125","decimal":"2.250","fractional":"5/4","malay":"-0.80","indonesian":"1.25","hongkong":"1.25"}},{"id":"294606236","description":"Philadelphia Flyers","status":"O","type":"H","competitorId":"3596982-510","price":{"id":"1836569814","american":"-155","decimal":"1.645161","fractional":"20/31","malay":"0.65","indonesian":"-1.55","hongkong":"0.65"}}]},{"id":"57349618","description":"Puck Line","key":"2W-HCAP","marketTypeId":"120744","status":"O","singleOnly":false,"notes":"","period":{"id":"1191","description":"Match","abbreviation":"M","live":false,"main":true},"outcomes":[{"id":"294606248","description":"New York Rangers","status":"O","type":"A","competitorId":"3596982-376","price":{"id":"1836755920","handicap":"1.5","american":"-210","decimal":"1.47619","fractional":"10/21","malay":"0.48","indonesian":"-2.10","hongkong":"0.48"}},{"id":"294606249","description":"Philadelphia Flyers","status":"O","type":"H","competitorId":"3596982-510","price":{"id":"1836569799","handicap":"-1.5","american":"+175"



In the example above the info I am looking for is 1.5 and -210 (for the New York Rangers), and -1.5 and +175 (for the Philadelphia Flyers).



Here is an example of the data I would like for one game:



                            Spread       Win         Total
New York Rangers +1.5 (-230) +130 O 6.0 (-105)
Philadelphia Flyers -1.5 (+190) -150 O 6.0 (-115)


I would like the same info for all of the games if possible.



I am new to scraping and have no prior experience coding. Any help will be greatly appreciated. Thanks in advance for your time and efforts!




  • Update:


Here is the URL: https://www.bovada.lv/sports/hockey



I am looking for the bet line info:



enter image description here










share|improve this question





























    1














    I am hoping for the following info:



    1) NHL Team Names



    2) Betting Odds



    Here is the site: https://www.bovada.lv/services/sports/event/v2/events/A/description/hockey/nhl.



    Here is my code so far:



    import requests

    source = requests.get("https://www.bovada.lv/services/sports/event/v2/events/A/description/hockey/nhl").json()

    data = source[0]

    for game in data['events'][2].items():
    print(game)


    The code above only prints the data for one game. I was hoping for all of the games. Is there an easy way to loop through all of them? I am also not sure how to parse out the info I am looking for.




    • Team Names


    I noticed the team names are located in the section titled 'competitors':



    competitors":[{"id":"3596982-510","name":"Philadelphia Flyers","home":true},{"id":"3596982-376","name":"New York Rangers","home":false}]


    In the example above the info I am looking for is Philadelphia Flyers and New York Rangers, respectively.




    • Odds


    (Note: the odds change so the numbers you see may be different)



    I also noticed the spread with odds is located in the section titled 'display groups':



    "displayGroups":[{"id":"100-128","description":"Game Lines","defaultType":true,"alternateType":false,"markets":[{"id":"57349611","description":"Total","key":"2W-OU","marketTypeId":"120743","status":"O","singleOnly":false,"notes":"","period":{"id":"1191","description":"Match","abbreviation":"M","live":false,"main":true},"outcomes":[{"id":"294606239","description":"Over","status":"O","type":"O","price":{"id":"1836755921","handicap":"6.5","american":"EVEN","decimal":"2.00","fractional":"1/1","malay":"1.00","indonesian":"1.00","hongkong":"1.00"}},{"id":"294606240","description":"Under","status":"O","type":"U","price":{"id":"1836755922","handicap":"6.5","american":"-125","decimal":"1.800","fractional":"4/5","malay":"0.80","indonesian":"-1.25","hongkong":"0.80"}}]},{"id":"57349614","description":"Moneyline","key":"2W-12","marketTypeId":"372","status":"O","singleOnly":false,"notes":"","period":{"id":"1191","description":"Match","abbreviation":"M","live":false,"main":true},"outcomes":[{"id":"294606235","description":"New York Rangers","status":"O","type":"A","competitorId":"3596982-376","price":{"id":"1836569815","american":"+125","decimal":"2.250","fractional":"5/4","malay":"-0.80","indonesian":"1.25","hongkong":"1.25"}},{"id":"294606236","description":"Philadelphia Flyers","status":"O","type":"H","competitorId":"3596982-510","price":{"id":"1836569814","american":"-155","decimal":"1.645161","fractional":"20/31","malay":"0.65","indonesian":"-1.55","hongkong":"0.65"}}]},{"id":"57349618","description":"Puck Line","key":"2W-HCAP","marketTypeId":"120744","status":"O","singleOnly":false,"notes":"","period":{"id":"1191","description":"Match","abbreviation":"M","live":false,"main":true},"outcomes":[{"id":"294606248","description":"New York Rangers","status":"O","type":"A","competitorId":"3596982-376","price":{"id":"1836755920","handicap":"1.5","american":"-210","decimal":"1.47619","fractional":"10/21","malay":"0.48","indonesian":"-2.10","hongkong":"0.48"}},{"id":"294606249","description":"Philadelphia Flyers","status":"O","type":"H","competitorId":"3596982-510","price":{"id":"1836569799","handicap":"-1.5","american":"+175"



    In the example above the info I am looking for is 1.5 and -210 (for the New York Rangers), and -1.5 and +175 (for the Philadelphia Flyers).



    Here is an example of the data I would like for one game:



                                Spread       Win         Total
    New York Rangers +1.5 (-230) +130 O 6.0 (-105)
    Philadelphia Flyers -1.5 (+190) -150 O 6.0 (-115)


    I would like the same info for all of the games if possible.



    I am new to scraping and have no prior experience coding. Any help will be greatly appreciated. Thanks in advance for your time and efforts!




    • Update:


    Here is the URL: https://www.bovada.lv/sports/hockey



    I am looking for the bet line info:



    enter image description here










    share|improve this question



























      1












      1








      1







      I am hoping for the following info:



      1) NHL Team Names



      2) Betting Odds



      Here is the site: https://www.bovada.lv/services/sports/event/v2/events/A/description/hockey/nhl.



      Here is my code so far:



      import requests

      source = requests.get("https://www.bovada.lv/services/sports/event/v2/events/A/description/hockey/nhl").json()

      data = source[0]

      for game in data['events'][2].items():
      print(game)


      The code above only prints the data for one game. I was hoping for all of the games. Is there an easy way to loop through all of them? I am also not sure how to parse out the info I am looking for.




      • Team Names


      I noticed the team names are located in the section titled 'competitors':



      competitors":[{"id":"3596982-510","name":"Philadelphia Flyers","home":true},{"id":"3596982-376","name":"New York Rangers","home":false}]


      In the example above the info I am looking for is Philadelphia Flyers and New York Rangers, respectively.




      • Odds


      (Note: the odds change so the numbers you see may be different)



      I also noticed the spread with odds is located in the section titled 'display groups':



      "displayGroups":[{"id":"100-128","description":"Game Lines","defaultType":true,"alternateType":false,"markets":[{"id":"57349611","description":"Total","key":"2W-OU","marketTypeId":"120743","status":"O","singleOnly":false,"notes":"","period":{"id":"1191","description":"Match","abbreviation":"M","live":false,"main":true},"outcomes":[{"id":"294606239","description":"Over","status":"O","type":"O","price":{"id":"1836755921","handicap":"6.5","american":"EVEN","decimal":"2.00","fractional":"1/1","malay":"1.00","indonesian":"1.00","hongkong":"1.00"}},{"id":"294606240","description":"Under","status":"O","type":"U","price":{"id":"1836755922","handicap":"6.5","american":"-125","decimal":"1.800","fractional":"4/5","malay":"0.80","indonesian":"-1.25","hongkong":"0.80"}}]},{"id":"57349614","description":"Moneyline","key":"2W-12","marketTypeId":"372","status":"O","singleOnly":false,"notes":"","period":{"id":"1191","description":"Match","abbreviation":"M","live":false,"main":true},"outcomes":[{"id":"294606235","description":"New York Rangers","status":"O","type":"A","competitorId":"3596982-376","price":{"id":"1836569815","american":"+125","decimal":"2.250","fractional":"5/4","malay":"-0.80","indonesian":"1.25","hongkong":"1.25"}},{"id":"294606236","description":"Philadelphia Flyers","status":"O","type":"H","competitorId":"3596982-510","price":{"id":"1836569814","american":"-155","decimal":"1.645161","fractional":"20/31","malay":"0.65","indonesian":"-1.55","hongkong":"0.65"}}]},{"id":"57349618","description":"Puck Line","key":"2W-HCAP","marketTypeId":"120744","status":"O","singleOnly":false,"notes":"","period":{"id":"1191","description":"Match","abbreviation":"M","live":false,"main":true},"outcomes":[{"id":"294606248","description":"New York Rangers","status":"O","type":"A","competitorId":"3596982-376","price":{"id":"1836755920","handicap":"1.5","american":"-210","decimal":"1.47619","fractional":"10/21","malay":"0.48","indonesian":"-2.10","hongkong":"0.48"}},{"id":"294606249","description":"Philadelphia Flyers","status":"O","type":"H","competitorId":"3596982-510","price":{"id":"1836569799","handicap":"-1.5","american":"+175"



      In the example above the info I am looking for is 1.5 and -210 (for the New York Rangers), and -1.5 and +175 (for the Philadelphia Flyers).



      Here is an example of the data I would like for one game:



                                  Spread       Win         Total
      New York Rangers +1.5 (-230) +130 O 6.0 (-105)
      Philadelphia Flyers -1.5 (+190) -150 O 6.0 (-115)


      I would like the same info for all of the games if possible.



      I am new to scraping and have no prior experience coding. Any help will be greatly appreciated. Thanks in advance for your time and efforts!




      • Update:


      Here is the URL: https://www.bovada.lv/sports/hockey



      I am looking for the bet line info:



      enter image description here










      share|improve this question















      I am hoping for the following info:



      1) NHL Team Names



      2) Betting Odds



      Here is the site: https://www.bovada.lv/services/sports/event/v2/events/A/description/hockey/nhl.



      Here is my code so far:



      import requests

      source = requests.get("https://www.bovada.lv/services/sports/event/v2/events/A/description/hockey/nhl").json()

      data = source[0]

      for game in data['events'][2].items():
      print(game)


      The code above only prints the data for one game. I was hoping for all of the games. Is there an easy way to loop through all of them? I am also not sure how to parse out the info I am looking for.




      • Team Names


      I noticed the team names are located in the section titled 'competitors':



      competitors":[{"id":"3596982-510","name":"Philadelphia Flyers","home":true},{"id":"3596982-376","name":"New York Rangers","home":false}]


      In the example above the info I am looking for is Philadelphia Flyers and New York Rangers, respectively.




      • Odds


      (Note: the odds change so the numbers you see may be different)



      I also noticed the spread with odds is located in the section titled 'display groups':



      "displayGroups":[{"id":"100-128","description":"Game Lines","defaultType":true,"alternateType":false,"markets":[{"id":"57349611","description":"Total","key":"2W-OU","marketTypeId":"120743","status":"O","singleOnly":false,"notes":"","period":{"id":"1191","description":"Match","abbreviation":"M","live":false,"main":true},"outcomes":[{"id":"294606239","description":"Over","status":"O","type":"O","price":{"id":"1836755921","handicap":"6.5","american":"EVEN","decimal":"2.00","fractional":"1/1","malay":"1.00","indonesian":"1.00","hongkong":"1.00"}},{"id":"294606240","description":"Under","status":"O","type":"U","price":{"id":"1836755922","handicap":"6.5","american":"-125","decimal":"1.800","fractional":"4/5","malay":"0.80","indonesian":"-1.25","hongkong":"0.80"}}]},{"id":"57349614","description":"Moneyline","key":"2W-12","marketTypeId":"372","status":"O","singleOnly":false,"notes":"","period":{"id":"1191","description":"Match","abbreviation":"M","live":false,"main":true},"outcomes":[{"id":"294606235","description":"New York Rangers","status":"O","type":"A","competitorId":"3596982-376","price":{"id":"1836569815","american":"+125","decimal":"2.250","fractional":"5/4","malay":"-0.80","indonesian":"1.25","hongkong":"1.25"}},{"id":"294606236","description":"Philadelphia Flyers","status":"O","type":"H","competitorId":"3596982-510","price":{"id":"1836569814","american":"-155","decimal":"1.645161","fractional":"20/31","malay":"0.65","indonesian":"-1.55","hongkong":"0.65"}}]},{"id":"57349618","description":"Puck Line","key":"2W-HCAP","marketTypeId":"120744","status":"O","singleOnly":false,"notes":"","period":{"id":"1191","description":"Match","abbreviation":"M","live":false,"main":true},"outcomes":[{"id":"294606248","description":"New York Rangers","status":"O","type":"A","competitorId":"3596982-376","price":{"id":"1836755920","handicap":"1.5","american":"-210","decimal":"1.47619","fractional":"10/21","malay":"0.48","indonesian":"-2.10","hongkong":"0.48"}},{"id":"294606249","description":"Philadelphia Flyers","status":"O","type":"H","competitorId":"3596982-510","price":{"id":"1836569799","handicap":"-1.5","american":"+175"



      In the example above the info I am looking for is 1.5 and -210 (for the New York Rangers), and -1.5 and +175 (for the Philadelphia Flyers).



      Here is an example of the data I would like for one game:



                                  Spread       Win         Total
      New York Rangers +1.5 (-230) +130 O 6.0 (-105)
      Philadelphia Flyers -1.5 (+190) -150 O 6.0 (-115)


      I would like the same info for all of the games if possible.



      I am new to scraping and have no prior experience coding. Any help will be greatly appreciated. Thanks in advance for your time and efforts!




      • Update:


      Here is the URL: https://www.bovada.lv/sports/hockey



      I am looking for the bet line info:



      enter image description here







      python json api parsing web-scraping






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 5 at 3:36









      Jake West

      236




      236










      asked Nov 22 at 20:03









      Able Archer

      968




      968
























          2 Answers
          2






          active

          oldest

          votes


















          2














          To get team name pairs try below:



          import requests

          source = requests.get("https://www.bovada.lv/services/sports/event/v2/events/A/description/hockey/nhl").json()

          data = source[0]
          for game in data:
          for team in data['events']:
          try:
          team_1 = team['competitors'][0]['name']
          team_2 = team['competitors'][1]['name']
          try: odd_1_1 = team['displayGroups'][0]['markets'][0]['outcomes'][0]['price']['handicap']
          except KeyError: odd_1_1 = None
          try: odd_1_2 = team['displayGroups'][0]['markets'][0]['outcomes'][0]['price']['american']
          except KeyError: odd_1_2 = None
          try: odd_2_1 = team['displayGroups'][0]['markets'][0]['outcomes'][1]['price']['handicap']
          except KeyError: odd_2_1 = None
          try: odd_2_2 = team['displayGroups'][0]['markets'][0]['outcomes'][1]['price']['american']
          except KeyError: odd_2_2 = None
          print("{0} ({2}, {3}) vs {1} ({4}, {5})".format(team_1,team_2, odd_1_1, odd_1_2, odd_2_1, odd_2_2))
          except IndexError:
          pass


          Output:



          Philadelphia Flyers (6.0, -115) vs New York Rangers (6.0, -105)
          Washington Capitals (1.5, -150) vs Detroit Red Wings (-1.5, +125)
          Anaheim Ducks (5.5, -110) vs Edmonton Oilers (5.5, -110)
          ...


          Note that in some entries competitors key has no value, so I used try/except to handle this case...






          share|improve this answer



















          • 1




            For now I cannot find required +1.5 -210 and -1.5 +175 under displayGroups... but I'll try to find :)
            – Andersson
            Nov 22 at 20:34










          • @Able Archer Can you tell me where exactly you found these values? :) Still cannot find them. Or they probably were updated...
            – Andersson
            Nov 22 at 20:45












          • The odds change @Andersson so the values might not be the same. I added a pic and the URL. Thanks for your help and I appreciate the try/except... Much respect!
            – Able Archer
            Nov 22 at 22:30












          • Your code is extremely helpful sir @Andersson. I am now able to print the teams like requested. My first request is complete... I would love to add the odds if possible. The info I am looking for is located after the words 'handicap' and 'american' (-1.5 and +175, for example).
            – Able Archer
            Nov 23 at 3:54










          • @AbleArcher , check updated. For some games handicap key might be absent, so I added some more try/except blocks to handle this issue.. It doesn't look pretty, but should work as expected :)
            – Andersson
            Nov 23 at 8:33





















          1














          This is a JSON formatted data, so use the python json module



          import json
          json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]')
          >>> ['foo', {'bar': ['baz', None, 1.0, 2]}]


          You can use the debugger to observe the datastructure, the loads(str) function will return. It will be a dict in your case. Then navigate in the lists and dictionaries.






          share|improve this answer





















          • Thanks for your response @handras! I will spend some time trying to learn from this.
            – Able Archer
            Nov 26 at 3:10











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437435%2fhow-to-scrape-nhl-team-names-and-odds-from-api%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          To get team name pairs try below:



          import requests

          source = requests.get("https://www.bovada.lv/services/sports/event/v2/events/A/description/hockey/nhl").json()

          data = source[0]
          for game in data:
          for team in data['events']:
          try:
          team_1 = team['competitors'][0]['name']
          team_2 = team['competitors'][1]['name']
          try: odd_1_1 = team['displayGroups'][0]['markets'][0]['outcomes'][0]['price']['handicap']
          except KeyError: odd_1_1 = None
          try: odd_1_2 = team['displayGroups'][0]['markets'][0]['outcomes'][0]['price']['american']
          except KeyError: odd_1_2 = None
          try: odd_2_1 = team['displayGroups'][0]['markets'][0]['outcomes'][1]['price']['handicap']
          except KeyError: odd_2_1 = None
          try: odd_2_2 = team['displayGroups'][0]['markets'][0]['outcomes'][1]['price']['american']
          except KeyError: odd_2_2 = None
          print("{0} ({2}, {3}) vs {1} ({4}, {5})".format(team_1,team_2, odd_1_1, odd_1_2, odd_2_1, odd_2_2))
          except IndexError:
          pass


          Output:



          Philadelphia Flyers (6.0, -115) vs New York Rangers (6.0, -105)
          Washington Capitals (1.5, -150) vs Detroit Red Wings (-1.5, +125)
          Anaheim Ducks (5.5, -110) vs Edmonton Oilers (5.5, -110)
          ...


          Note that in some entries competitors key has no value, so I used try/except to handle this case...






          share|improve this answer



















          • 1




            For now I cannot find required +1.5 -210 and -1.5 +175 under displayGroups... but I'll try to find :)
            – Andersson
            Nov 22 at 20:34










          • @Able Archer Can you tell me where exactly you found these values? :) Still cannot find them. Or they probably were updated...
            – Andersson
            Nov 22 at 20:45












          • The odds change @Andersson so the values might not be the same. I added a pic and the URL. Thanks for your help and I appreciate the try/except... Much respect!
            – Able Archer
            Nov 22 at 22:30












          • Your code is extremely helpful sir @Andersson. I am now able to print the teams like requested. My first request is complete... I would love to add the odds if possible. The info I am looking for is located after the words 'handicap' and 'american' (-1.5 and +175, for example).
            – Able Archer
            Nov 23 at 3:54










          • @AbleArcher , check updated. For some games handicap key might be absent, so I added some more try/except blocks to handle this issue.. It doesn't look pretty, but should work as expected :)
            – Andersson
            Nov 23 at 8:33


















          2














          To get team name pairs try below:



          import requests

          source = requests.get("https://www.bovada.lv/services/sports/event/v2/events/A/description/hockey/nhl").json()

          data = source[0]
          for game in data:
          for team in data['events']:
          try:
          team_1 = team['competitors'][0]['name']
          team_2 = team['competitors'][1]['name']
          try: odd_1_1 = team['displayGroups'][0]['markets'][0]['outcomes'][0]['price']['handicap']
          except KeyError: odd_1_1 = None
          try: odd_1_2 = team['displayGroups'][0]['markets'][0]['outcomes'][0]['price']['american']
          except KeyError: odd_1_2 = None
          try: odd_2_1 = team['displayGroups'][0]['markets'][0]['outcomes'][1]['price']['handicap']
          except KeyError: odd_2_1 = None
          try: odd_2_2 = team['displayGroups'][0]['markets'][0]['outcomes'][1]['price']['american']
          except KeyError: odd_2_2 = None
          print("{0} ({2}, {3}) vs {1} ({4}, {5})".format(team_1,team_2, odd_1_1, odd_1_2, odd_2_1, odd_2_2))
          except IndexError:
          pass


          Output:



          Philadelphia Flyers (6.0, -115) vs New York Rangers (6.0, -105)
          Washington Capitals (1.5, -150) vs Detroit Red Wings (-1.5, +125)
          Anaheim Ducks (5.5, -110) vs Edmonton Oilers (5.5, -110)
          ...


          Note that in some entries competitors key has no value, so I used try/except to handle this case...






          share|improve this answer



















          • 1




            For now I cannot find required +1.5 -210 and -1.5 +175 under displayGroups... but I'll try to find :)
            – Andersson
            Nov 22 at 20:34










          • @Able Archer Can you tell me where exactly you found these values? :) Still cannot find them. Or they probably were updated...
            – Andersson
            Nov 22 at 20:45












          • The odds change @Andersson so the values might not be the same. I added a pic and the URL. Thanks for your help and I appreciate the try/except... Much respect!
            – Able Archer
            Nov 22 at 22:30












          • Your code is extremely helpful sir @Andersson. I am now able to print the teams like requested. My first request is complete... I would love to add the odds if possible. The info I am looking for is located after the words 'handicap' and 'american' (-1.5 and +175, for example).
            – Able Archer
            Nov 23 at 3:54










          • @AbleArcher , check updated. For some games handicap key might be absent, so I added some more try/except blocks to handle this issue.. It doesn't look pretty, but should work as expected :)
            – Andersson
            Nov 23 at 8:33
















          2












          2








          2






          To get team name pairs try below:



          import requests

          source = requests.get("https://www.bovada.lv/services/sports/event/v2/events/A/description/hockey/nhl").json()

          data = source[0]
          for game in data:
          for team in data['events']:
          try:
          team_1 = team['competitors'][0]['name']
          team_2 = team['competitors'][1]['name']
          try: odd_1_1 = team['displayGroups'][0]['markets'][0]['outcomes'][0]['price']['handicap']
          except KeyError: odd_1_1 = None
          try: odd_1_2 = team['displayGroups'][0]['markets'][0]['outcomes'][0]['price']['american']
          except KeyError: odd_1_2 = None
          try: odd_2_1 = team['displayGroups'][0]['markets'][0]['outcomes'][1]['price']['handicap']
          except KeyError: odd_2_1 = None
          try: odd_2_2 = team['displayGroups'][0]['markets'][0]['outcomes'][1]['price']['american']
          except KeyError: odd_2_2 = None
          print("{0} ({2}, {3}) vs {1} ({4}, {5})".format(team_1,team_2, odd_1_1, odd_1_2, odd_2_1, odd_2_2))
          except IndexError:
          pass


          Output:



          Philadelphia Flyers (6.0, -115) vs New York Rangers (6.0, -105)
          Washington Capitals (1.5, -150) vs Detroit Red Wings (-1.5, +125)
          Anaheim Ducks (5.5, -110) vs Edmonton Oilers (5.5, -110)
          ...


          Note that in some entries competitors key has no value, so I used try/except to handle this case...






          share|improve this answer














          To get team name pairs try below:



          import requests

          source = requests.get("https://www.bovada.lv/services/sports/event/v2/events/A/description/hockey/nhl").json()

          data = source[0]
          for game in data:
          for team in data['events']:
          try:
          team_1 = team['competitors'][0]['name']
          team_2 = team['competitors'][1]['name']
          try: odd_1_1 = team['displayGroups'][0]['markets'][0]['outcomes'][0]['price']['handicap']
          except KeyError: odd_1_1 = None
          try: odd_1_2 = team['displayGroups'][0]['markets'][0]['outcomes'][0]['price']['american']
          except KeyError: odd_1_2 = None
          try: odd_2_1 = team['displayGroups'][0]['markets'][0]['outcomes'][1]['price']['handicap']
          except KeyError: odd_2_1 = None
          try: odd_2_2 = team['displayGroups'][0]['markets'][0]['outcomes'][1]['price']['american']
          except KeyError: odd_2_2 = None
          print("{0} ({2}, {3}) vs {1} ({4}, {5})".format(team_1,team_2, odd_1_1, odd_1_2, odd_2_1, odd_2_2))
          except IndexError:
          pass


          Output:



          Philadelphia Flyers (6.0, -115) vs New York Rangers (6.0, -105)
          Washington Capitals (1.5, -150) vs Detroit Red Wings (-1.5, +125)
          Anaheim Ducks (5.5, -110) vs Edmonton Oilers (5.5, -110)
          ...


          Note that in some entries competitors key has no value, so I used try/except to handle this case...







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 23 at 8:26

























          answered Nov 22 at 20:33









          Andersson

          36.9k103266




          36.9k103266








          • 1




            For now I cannot find required +1.5 -210 and -1.5 +175 under displayGroups... but I'll try to find :)
            – Andersson
            Nov 22 at 20:34










          • @Able Archer Can you tell me where exactly you found these values? :) Still cannot find them. Or they probably were updated...
            – Andersson
            Nov 22 at 20:45












          • The odds change @Andersson so the values might not be the same. I added a pic and the URL. Thanks for your help and I appreciate the try/except... Much respect!
            – Able Archer
            Nov 22 at 22:30












          • Your code is extremely helpful sir @Andersson. I am now able to print the teams like requested. My first request is complete... I would love to add the odds if possible. The info I am looking for is located after the words 'handicap' and 'american' (-1.5 and +175, for example).
            – Able Archer
            Nov 23 at 3:54










          • @AbleArcher , check updated. For some games handicap key might be absent, so I added some more try/except blocks to handle this issue.. It doesn't look pretty, but should work as expected :)
            – Andersson
            Nov 23 at 8:33
















          • 1




            For now I cannot find required +1.5 -210 and -1.5 +175 under displayGroups... but I'll try to find :)
            – Andersson
            Nov 22 at 20:34










          • @Able Archer Can you tell me where exactly you found these values? :) Still cannot find them. Or they probably were updated...
            – Andersson
            Nov 22 at 20:45












          • The odds change @Andersson so the values might not be the same. I added a pic and the URL. Thanks for your help and I appreciate the try/except... Much respect!
            – Able Archer
            Nov 22 at 22:30












          • Your code is extremely helpful sir @Andersson. I am now able to print the teams like requested. My first request is complete... I would love to add the odds if possible. The info I am looking for is located after the words 'handicap' and 'american' (-1.5 and +175, for example).
            – Able Archer
            Nov 23 at 3:54










          • @AbleArcher , check updated. For some games handicap key might be absent, so I added some more try/except blocks to handle this issue.. It doesn't look pretty, but should work as expected :)
            – Andersson
            Nov 23 at 8:33










          1




          1




          For now I cannot find required +1.5 -210 and -1.5 +175 under displayGroups... but I'll try to find :)
          – Andersson
          Nov 22 at 20:34




          For now I cannot find required +1.5 -210 and -1.5 +175 under displayGroups... but I'll try to find :)
          – Andersson
          Nov 22 at 20:34












          @Able Archer Can you tell me where exactly you found these values? :) Still cannot find them. Or they probably were updated...
          – Andersson
          Nov 22 at 20:45






          @Able Archer Can you tell me where exactly you found these values? :) Still cannot find them. Or they probably were updated...
          – Andersson
          Nov 22 at 20:45














          The odds change @Andersson so the values might not be the same. I added a pic and the URL. Thanks for your help and I appreciate the try/except... Much respect!
          – Able Archer
          Nov 22 at 22:30






          The odds change @Andersson so the values might not be the same. I added a pic and the URL. Thanks for your help and I appreciate the try/except... Much respect!
          – Able Archer
          Nov 22 at 22:30














          Your code is extremely helpful sir @Andersson. I am now able to print the teams like requested. My first request is complete... I would love to add the odds if possible. The info I am looking for is located after the words 'handicap' and 'american' (-1.5 and +175, for example).
          – Able Archer
          Nov 23 at 3:54




          Your code is extremely helpful sir @Andersson. I am now able to print the teams like requested. My first request is complete... I would love to add the odds if possible. The info I am looking for is located after the words 'handicap' and 'american' (-1.5 and +175, for example).
          – Able Archer
          Nov 23 at 3:54












          @AbleArcher , check updated. For some games handicap key might be absent, so I added some more try/except blocks to handle this issue.. It doesn't look pretty, but should work as expected :)
          – Andersson
          Nov 23 at 8:33






          @AbleArcher , check updated. For some games handicap key might be absent, so I added some more try/except blocks to handle this issue.. It doesn't look pretty, but should work as expected :)
          – Andersson
          Nov 23 at 8:33















          1














          This is a JSON formatted data, so use the python json module



          import json
          json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]')
          >>> ['foo', {'bar': ['baz', None, 1.0, 2]}]


          You can use the debugger to observe the datastructure, the loads(str) function will return. It will be a dict in your case. Then navigate in the lists and dictionaries.






          share|improve this answer





















          • Thanks for your response @handras! I will spend some time trying to learn from this.
            – Able Archer
            Nov 26 at 3:10
















          1














          This is a JSON formatted data, so use the python json module



          import json
          json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]')
          >>> ['foo', {'bar': ['baz', None, 1.0, 2]}]


          You can use the debugger to observe the datastructure, the loads(str) function will return. It will be a dict in your case. Then navigate in the lists and dictionaries.






          share|improve this answer





















          • Thanks for your response @handras! I will spend some time trying to learn from this.
            – Able Archer
            Nov 26 at 3:10














          1












          1








          1






          This is a JSON formatted data, so use the python json module



          import json
          json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]')
          >>> ['foo', {'bar': ['baz', None, 1.0, 2]}]


          You can use the debugger to observe the datastructure, the loads(str) function will return. It will be a dict in your case. Then navigate in the lists and dictionaries.






          share|improve this answer












          This is a JSON formatted data, so use the python json module



          import json
          json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]')
          >>> ['foo', {'bar': ['baz', None, 1.0, 2]}]


          You can use the debugger to observe the datastructure, the loads(str) function will return. It will be a dict in your case. Then navigate in the lists and dictionaries.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 at 20:09









          handras

          373115




          373115












          • Thanks for your response @handras! I will spend some time trying to learn from this.
            – Able Archer
            Nov 26 at 3:10


















          • Thanks for your response @handras! I will spend some time trying to learn from this.
            – Able Archer
            Nov 26 at 3:10
















          Thanks for your response @handras! I will spend some time trying to learn from this.
          – Able Archer
          Nov 26 at 3:10




          Thanks for your response @handras! I will spend some time trying to learn from this.
          – Able Archer
          Nov 26 at 3:10


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437435%2fhow-to-scrape-nhl-team-names-and-odds-from-api%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          What visual should I use to simply compare current year value vs last year in Power BI desktop

          How to ignore python UserWarning in pytest?

          Alexandru Averescu