Program inefficiency?

George Sakkis george.sakkis at gmail.com
Sun Sep 30 00:53:07 CEST 2007


On Sep 29, 2:32 pm, hall.j... at gmail.com 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




More information about the Python-list mailing list