逆は、次のようにpyparsingを使用して実現できます。
from pyparsing import Suppress, replaceWith, makeHTMLTags, SkipTo
#...
removeText = replaceWith("")
scriptOpen, scriptClose = makeHTMLTags("script")
scriptBody = scriptOpen + SkipTo(scriptClose) + scriptClose
scriptBody.setParseAction(removeText)
data = (scriptBody).transformString(data)
タグの内容を保持するにはどうすればよい"table"
ですか?
更新0:
試しました:#テーブルのみを保持tableOpen、tableClose = makeHTMLTags( "table")tableBody = tableOpen + SkipTo(tableClose)+ tableClose f = replaceWith(tableBody)tableBody.setParseAction(f)data =(tableBody).transformString(data)データを印刷する
そして、私はこのようなものを手に入れます...
garbages
<input type="hidden" name="cassstx" value="en_US:frontend"></form></td></tr></table></span></td></tr></table>
{<"table"> SkipTo:(</"table">) </"table">}
<div id="asbnav" style="padding-bottom: 10px;">{<"table"> SkipTo:(</"table">) </"table">}
</div>
even more garbages
更新2:
Martelliに感謝します。私が必要なのは:
from pyparsing import Suppress, replaceWith, makeHTMLTags, SkipTo
#...
data = 'before<script>ciao<table>buh</table>bye</script>after'
tableOpen, tableClose = makeHTMLTags("table")
tableBody = tableOpen + SkipTo(tableClose) + tableClose
thetable = (tableBody).searchString(data)[0][2]
print thetable