我使用BeautifulSoup从我的元素中删除内联高度和宽度。解决它的图像很简单:从内联样式中删除高度和宽度
def remove_dimension_tags(tag):
for attribute in ["width", "height"]:
del tag[attribute]
return tag
但我不知道如何去处理这样的事情:
<div id="attachment_9565" class="wp-caption aligncenter" style="width: 2010px;background-color:red">
,当我要离开的背景颜色(例如)或除高度或宽度以外的任何其他样式属性。
我能想到的唯一方法就是使用正则表达式,但是上次我提出了这样的想法,StackOverflow的精神从我的计算机中出来并杀死了我的第一胎。
如果我_am_应该使用正则表达式...有一点帮助,将不胜感激。 – thumbtackthief
我没有看到使用正则表达式_on风格attribute_的内容有任何问题,但使用BeautifulSoup找到该属性。 – Ben