Help Parsing Data from Table on Web-Page

41 views
Skip to first unread message

Jim T

unread,
Apr 3, 2018, 5:42:39 PM4/3/18
to beautifulsoup
Hi…

I'm trying to use Python and BeautifulSoup to try and parse some information from a pretty basic web-site.
I'm very new to both Python and BeautifulSoup and could use some advice/instruction.

I've included a screen shot (at the bottom) showing the element tree from the web-browser.
The data I want is contained in a table that is nested inside another table. It starts on the 5th row and then on  the 7th, 9th, 11th, 13th, 15th.
The 16th and 20th rows are single-value rows
Then on the 16th, 18th, 20th, 22ndetc….
There are 4 TD definitions on each row.  The first 2 can be identified by class=jackpot2 and the 3rd one by class=jackpot.
What I want to do, is parse each data-bearing row for those 3 pieces of information (GameName, TargetNumber, Prize).

So far - what I have is:
Jackpot2 = soup.select('.jackpot2, .jackpot')
       
for tag in jackpot2:
            _LOGGER
.debug("Jackpot2: " + tag.text.strip())
(Log snippet showing output of this code appears below)

This returns a dictionary with the data I want in it - but I don't think I can trust the order.
As you can see, all of the 'jackpot' values appear at the end of the list instead of inline with the GameName and TargetNumber information.
I may be able to work with this if I have to - but I was hoping that someone more knowledgeable could suggest a more elegant way of doing this?

Is there a query syntax that would work here for me to pull a single, but complete <TR> if it contains "Double Action" (for example)?
If so - I could just pull each TR individually, parse what I need from it and then do the next one.  The "GameName" will always be the same - but the TargetNumber and Prize amounts will change.

Any help or advice would be appreciated.

The website I am trying to pull the data from is:

Thanks,
Jim


<Log Snippet>
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: Double Action
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: 33
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: Early Bird Jackpot
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: 50
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: Mega Balls Des #
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: 5
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: Mega Balls Pull Tab 1
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: 0
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: Mega Balls Pull Tab 2
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: 
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: POD Progressive
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: Progressive
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: 48
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: Progressive X
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: 14
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: Rapid Bonus
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: RH Progressive
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: Super Jackpot I
Session Time10:00PM
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: 54
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: Super Jackpot II
Session Time7:00pm
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: Taptix Progressive
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: Toonie Pot
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: Turbo Challenge
Session Time6:30PM
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: 7
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: $5,000.00
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: $1,500.00
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: $4,500.00
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: $2,200.00
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: $7,550.00
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: $4,168.00
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: $8,081.00
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: $111.00
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: $3,000.00
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: $8,100.00
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: $200.00
2018-04-03 16:03:16 DEBUG (Thread-6) [custom_components.sensor.bwrh] Jackpot2: $1,259.00




Reply all
Reply to author
Forward
0 new messages