For new recipes it does not matter, since new recipes are only available once a new release of calibre is made, just use bs4.
For updating old recipes, one just has to be a bit careful to write code that works for both. The main incompatibilities are creating Tag objects and directly check class values
For creating Tag objects, use this wrapper function, which works with both bs3 and bs4.
Code:
def new_tag(soup, name, attrs=()):
impl = getattr(soup, 'new_tag', None)
if impl is not None:
return impl(name, attrs=dict(attrs))
return Tag(soup, name, attrs=attrs or None)
If you wish to directly check if the clas attribute of a tag has a value, use somethinglike:
Code:
def check_in(tag, attr, val):
q = tag[attr]
if not isinstance(q, list):
q = q.split()
return attr in q