我使用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