I want to call a Beautiful Soup attributes (eg. class_, href, id) from a variable to use it in functions such as this one:
script
from b
all credit to MYGz and commandlineluser
from bs4 import BeautifulSoup
data='xxx
yyy
zzz
'
def removeAttrib(data, tag, kwargs):
soup = BeautifulSoup(data, "html.parser")
for x in soup.findAll(tag, kwargs):
for key in kwargs:
# print(key) #>>class
x.attrs.pop(key, None) # attrs: to access the actual dict
#del x[key] would work also but will throw a KeyError if no key
print(soup)
return soup
data=removeAttrib(data,"p",{"class":"story"})