Skip to content
Advertisement

Can this beautifulsoup script be simplified with Regex?

I wrote some beautifulsoup scripts, and one part seems really redundant, I am thinking if it can be simplified with Regex.

All posts from this forum are marked with different colors, what I did is to search each color with one line. For six colors I did six lines with only one words difference.

JavaScript

I am not sure if it is possible to be simplified. Maybe something like:

JavaScript

if it’s not regex, or could it be something else?

This is partial DOM:

JavaScript

Advertisement

Answer

You can pass a attribute list to css select with ends with operator

JavaScript

So,

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