Skip to content
Advertisement

Python scraping – subtract class?

I am new to python and programming and scraping. I would like to subtract one html tag from another: in “game_elements” there are all matches including lives, in “game_elements_live” there are only lives. In your opinion is it possible to only have non-live matches? I use requests and BeautifulSoup thank you so much

game_elements = html.select(".cardEvent.prebootFreeze.ng-star-inserted")
game_elements_live = html.select(".cardEvent.prebootFreeze.ng-star-inserted.is-live")   

Advertisement

Answer

If you’re using version 4.7.0 or later of Beautiful Soup, the select method should support the :not() selector, in which case game_elements = html.select(".cardEvent.prebootFreeze.ng-star-inserted:not(.is-live)") should work

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement