def make_soup(markup, parser=None):
"""Factory method returning a BeautifulSoup instance. The created
instance will use a parser of the given name, if supported by
the underlying BeautifulSoup instance.
"""
if 'bs4' in sys.modules:
# We support parser specification. If the caller didn't
# specify one, leave it to BeautifulSoup to pick the most
# suitable one, but suppress the user warning that asks to
# select the most suitable parser ... which BS then
# selects anyway.
if parser is None:
warnings.filterwarnings('ignore', 'No parser was explicitly specified')
return BeautifulSoup(markup, parser)
return BeautifulSoup(markup)
评论列表
文章目录