I'm scraping an HTML webpage. I'm using the BeautifulSoup lib (4.6.0) and Python (3.7) on a Mac (Sierra).
Among other things, I see a bunch of 'div' tags which have class attributes. Some of the 'div' tags come with multiple class attribute values. Now I want to filter based on tag name and class attribute values, e.g. I want to find the 'div' tags that have class='a' but not class='b' (and, yes, some of the div tags come with class='a b').
To get those tags I tried to use a filtering function as mention in the BS4 documentation (https://www.crummy.com/software/BeautifulSoup/bs4/doc/#a-function). I'm under the impression that find_all() passes a bs4 tag element to the function and within the function you can do whatever you would do on a BS4 tag element. That seems not to be true. I get a string and obviously all my BS4 tag element operations raise an exception.
Two questions:
- What exactly does find_all() pass to the function and how can the argument be used?
- Besides a function how would otherwise be able to achieve the desired functionality?