how to remove <BR> using replace function?

bruno at modulix onurb at xiludom.gro
Thu Feb 9 04:50:26 EST 2006


localpricemaps at gmail.com wrote:
> 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()

Why concatening ?

>             strTitle = string.replace(strTitle,'<br>','')

Use strTitle.replace('<br>', '') instead. And BTW, hungarian notation is
evil, so:
for text in incident.fetchText(...):
   title = text.strip().replace('<br>', '')



> but it doesn't seem to remove the <br>

it does :

Python 2.4.2 (#1, Feb  9 2006, 02:40:32)
[GCC 3.4.5 (Gentoo 3.4.5, ssp-3.4.5-1.0, pie-8.7.9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> s = '<address style="color:#">34 main,<br> Boston, MA</address>'
>>> s.replace('<br>', '')
'<address style="color:#">34 main, Boston, MA</address>'
>>>

The problem is obviously not with str.replace(), as you could have
figured out by yourself very easily.

> any ideas?

yes: post the minimal *running* code that exhibit the problem.

Your problem is probably elsewhere, and given some of previous posts
here ('problems writing tuple to log file' and 'indentation messing up
my tuple?'), I'd say that a programming101 course should be your first
move.


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list