The HTML looks a little like this: (there's a vast many more stats etc, but this is the first one)
<div id="statistics-content">
<div class="statTextGroup">
<div class="statText statText--homeValue">53%</div>
<div class="statText statText--titleValue">Ball Possession</div>
<div class="statText statText--awayValue">47%</div>
</div>
I'd like to draw out the 53% (without the % symbol if possible) as a home team value. Then I'd like to draw out the 47% (also without the % symbol if possible) as the away team value.
I can add the Ball Possession words later - or, if there's an easy way to append Ball Possession from this list, then I will do that too.
So, I did try this:
home_stats = soup.select_one('#statistics-content .statText--homeValue:nth-child(1)').text
And I searched the resultant error:
home_stats = soup.select_one('#statistics-content .statText--homeValue:nth-child(1)').text
AttributeError: 'NoneType' object has no attribute 'text'
But I can not seem to find something that fits this particular situation. My previous attempts have worked using this similar method, but they were either in a span or an a tag and had attributes. But this is just text wrapped in a div.
I can not change the HTML (sadly) - so I need to parse it directly from that HTML if possible.
The final outcome should look like:
[home_team] had 53% ball possession and [away_team] had 47% ball possession
Both home and away team works to give the correct name. I'd like "ball possession" to be all lower case and I'd like to add the % myself as I want to use those numbers separately later.
The code is all there, just not scraping the correct data. There's 14 other stats I'd like to retrieve, so hopefully, if I get this one right, then nth-child(x) should work.
Thanks kindly - this is very much my beginning journey of python and webscraping, so all help is appreciated.
To make it easier, I am scraping now from this site: https://www.scoreboard.com/en/match/SO3Fg7NR/#match-statistics;0