Re: Program inefficiency?



On Sep 29, 2:32 pm, hall.j...@xxxxxxxxx wrote:

It think he's saying it should look like this:

(line noise snipped)

Or you can let BeautifulSoup do the dirty job for you and forget all
this ugliness:


from BeautifulSoup import BeautifulSoup

soup = BeautifulSoup(text)
for a in soup.findAll('a'):
for attr in 'href','name':
val = a.get(attr)
if val:
a[attr] = val.replace(' ','_')
print soup


George

.



Relevant Pages

  • Re: Removing certain tags from html files
    ... I think BeautifulSoup isn't good for that because it ... for tag in soup.findAll: ... No regular expressions are not a very good idea. ...
    (comp.lang.python)
  • Re: Parsing HTML - modify URLs
    ... > "You can modify a Tag or NavigableText in place. ... > string will print the new markup text." ... this will do the job on the BeautifulSoup ...
    (comp.lang.python)
  • Re: Parsing HTML - modify URLs
    ... > "You can modify a Tag or NavigableText in place. ... this will do the job on the BeautifulSoup ... Brilliant Richard. ...
    (comp.lang.python)