I am currently learning web scraping using Python and Beautiful Soup. I am given a task in which the web page is having star rating inside css pseudo element
<span class="bb_rating bble_50">
::before
::after
</span>
bble_50::after {
content: "\e00b\e00b\e00b\e00b\e00b";
}
I want to know how can I get the content from css psuedo element? Need help. Thanks
I don't think you should actually go to parsing CSS here. Just map out the class names to ratings:
class_to_rating = {
"bble_45": 4.5,
"bble_50": 5
}
elm = soup.select_one(".bb_rating")
rating_class = next(value for value in elm["class"] if value.startswith("bble_"))
print(class_to_rating.get(rating_class, "Unknown rating"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With