Python Forum
web scraping football results and odds
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
web scraping football results and odds
#1
Hello,
I am extracting football results with their odds, I have created 2 for-loops, one for the extraction of team names and results and one for the odds. Every single for loop works well, but I don't know how I can combine them together to get the correct output.

This is my code:
from requests_html import HTMLSession
import tabulate
from tabulate import tabulate

matchlink = 'https://www.betexplorer.com/football/england/league-one/results/'

session = HTMLSession()

r = session.get(matchlink)


allmatch = r.html.find('.in-match')
results = r.html.find('.h-text-center a')
matchodds = r.html.find('.table-main__odds')

odds = [matchodd.text for matchodd in matchodds]



for match, res in zip(allmatch, results):   #works
    for i in range(0, len(odds), 3): 
        if res.text == 'POSTP.':
            continue

    print(match.text, res.text, odds[i:i+3])
My actual output is (this is a little part):
Quote:Wigan - Peterborough 2:1 ['2.09', '3.45', '3.37']
Reading - Bristol Rovers 1:1 ['2.09', '3.45', '3.37']
Shrewsbury - Bolton 0:2 ['2.09', '3.45', '3.37']
Fleetwood - Blackpool 3:3 ['2.09', '3.45', '3.37']
Derby - Northampton 4:0 ['2.09', '3.45', '3.37']
Lincoln - Oxford Utd 0:2 ['2.09', '3.45', '3.37']

You can see that I get the same odds for each match, and it's not correct.

My goal is the follow output (this is a little part):
Quote:Wigan - Peterborough 2:1 ['2.97', '3.57', '2.23']
Reading - Bristol Rovers 1:1 ['2.57', '3.51', '2.54']
Shrewsbury - Bolton 0:2 ['3.71', '3.47', '1.98']
Fleetwood - Blackpool 3:3 ['3.26', '3.25', '2.22']
Derby - Northampton 4:0 ['1.54', '3.91', '6.24']
Lincoln - Oxford Utd 0:2 ['3.28', '3.18', '2.25']

is it also possible to have odds without square brackets?

Thanks
Reply
#2
Sleepy
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Web scraping for search results JOE 7 3,300 May-14-2022, 01:19 PM
Last Post: JOE
  Web Scraping (Results not appearing) TheBadLeopard 4 2,762 Oct-17-2019, 04:56 PM
Last Post: TheBadLeopard
  Scraping daily football score shamil1999 2 2,753 Sep-18-2019, 09:55 AM
Last Post: Larz60+
  Scrap arbitrage odds -help Gochix2020 3 2,885 Jul-31-2019, 10:45 AM
Last Post: Gochix2020

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020