如何删除< BR>使用替换功能?
问题描述:
我有一些看起来像这样的HTML
< address style =" color:#"> 34 main,< br>波士顿,马萨诸塞州< / address>
我试图使用替换功能来摆脱< br>那个
i使用这段代码:
for fact.fetchText(oRE)中的oText:
strTitle + = oText。 strip()
strTitle = string.replace(strTitle,''< br>'','''')
但它没有'''似乎删除了< br>
任何想法?
i have some html that looks like this
<address style="color:#">34 main,<br> Boston, MA</address>
and i am trying to use the replace function to get rid of the <Br> that
i scrape out using this code:
for oText in incident.fetchText( oRE):
strTitle += oText.strip()
strTitle = string.replace(strTitle,''<br>'','''')
but it doesn''t seem to remove the <br>
any ideas?
答
I我想你想使用字符串实例的替换方法。
这样的东西会起作用:
#参见 http://docs.python.org/lib/string-methods.html#l2h-196
txt =" a unfortunate< br>在中间
txt = txt.replace("< br>","")
I think you want to use the replace method of the string instance.
Something like this will work:
# See http://docs.python.org/lib/string-methods.html#l2h-196
txt = "an unfortunate <br> in the middle"
txt = txt.replace("<br>", "")
尝试过,对我不起作用
tried that, didn''t work for me
nope不起作用
nope didn''t work