편집 :
나는과 비교할 W3에서 모든 html 태그의 전체 (적어도이 완료되어야합니다) 목록을 잡았다. (
</endtag>
를)
>>> print s
<tr>
td>LABEL1</td><td>INPUT1</td>
</tr>
<tr>
<td>LABEL2</td><td>INPUT2</td>
</tr>
>>> print re.sub(">\s*(\!--|\!DOCTYPE|\
a|abbr|acronym|address|applet|area|\
b|base|basefont|bdo|big|blockquote|body|br|button|\
caption|center|cite|code|col|colgroup|\
dd|del|dfn|dir|div|dl|dt|\
em|\
fieldset|font|form|frame|frameset|\
head|h1|h2|h3|h4|h5|h6|hr|html|\
i|iframe|img|input|ins|\
kbd|\
label|legend|li|link|\
map|menu|meta|\
noframes|noscript|\
object|ol|optgroup|option|\
p|param|pre|\
q|\
s|samp|script|select|small|span|strike|strong|style|sub|sup|\
table|tbody|td|textarea|tfoot|th|thead|title|tr|tt|\
u|ul|\
var)>", "><\g<1>>", s)
<tr><td>LABEL1</td><td>INPUT1</td>
</tr>
<tr>
<td>LABEL2</td><td>INPUT2</td>
</tr>
이 일뿐만 아니라 깨진 끝 태그와 일치해야합니다 :
fixedString = re.sub(">\s*(\!--|\!DOCTYPE|\
a|abbr|acronym|address|applet|area|\
b|base|basefont|bdo|big|blockquote|body|br|button|\
caption|center|cite|code|col|colgroup|\
dd|del|dfn|dir|div|dl|dt|\
em|\
fieldset|font|form|frame|frameset|\
head|h1|h2|h3|h4|h5|h6|hr|html|\
i|iframe|img|input|ins|\
kbd|\
label|legend|li|link|\
map|menu|meta|\
noframes|noscript|\
object|ol|optgroup|option|\
p|param|pre|\
q|\
s|samp|script|select|small|span|strike|strong|style|sub|sup|\
table|tbody|td|textarea|tfoot|th|thead|title|tr|tt|\
u|ul|\
var)>", "><\g<1>>", s)
bs = BeautifulSoup(fixedString)
가 생산 : 그것을 밖으로 시도
re.sub(">\s*(/?)(\!--|\!DOCTYPE|\a|abbr|acronym|address|applet|area|\
b|base|basefont|bdo|big|blockquote|body|br|button|\
caption|center|cite|code|col|colgroup|\
dd|del|dfn|dir|div|dl|dt|\
em|\
fieldset|font|form|frame|frameset|\
head|h1|h2|h3|h4|h5|h6|hr|html|\
i|iframe|img|input|ins|\
kbd|\
label|legend|li|link|\
map|menu|meta|\
noframes|noscript|\
object|ol|optgroup|option|\
p|param|pre|\
q|\
s|samp|script|select|small|span|strike|strong|style|sub|sup|\
table|tbody|td|textarea|tfoot|th|thead|title|tr|tt|\
u|ul|\
var)>", "><\g<1>\g<2>>", s)
행운을 빈다. 출력 : <><><><<><><><><><><<><><> – howtodothis
@terra @ regex를 수정하고 내 대답을 편집하여 지금 내가 가지고있는 re.sub를 시험해보십시오. 나는 그것을 테스트하고 꽤 잘 작동합니다. 모든 html 태그의 전체 목록을 확인합니다 (w3에서 가져옴). – chown