"outline-style: none; margin: 0px; padding: 2px; background-color: #eff0f8; color: #3b3a39; font-family: Georgia,'Times New Roman',Times,serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: center; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border: 1px solid #ebebeb; float: left;"
我有这个内联的CSS。我想用正则表达式来替换所有以“background”和“font”开头的属性的空格。在内嵌CSS,最后一个属性可能不会有分号作为结束如何使用正则表达式删除一些CSS属性?
我使用此代码作为Django的过滤器除去从服务器端的这些属性使用美丽的汤
def html_remove_attrs(value):
soup = BeautifulSoup(value)
print "hi"
for tag in soup.findAll(True,{'style': re.compile(r'')}):
#tag.attrs = None
#for attr in tag.attrs:
# if "class" in attr:
# tag.attrs.remove(attr)
# if "style" in attr:
# tag.attrs.remove(attr)
for attr in tag.attrs:
if "style" in attr:
#remove the background and font properties
return soup
你在做这个之前,去居住或当它击中的客户端(JavaScript?) – Jakub
我必须从服务器端解析它.. –
您应该重新考虑使用'内联css'来支持可重用类。 – Jakub