Re: [Tutor] BeautifulSoup - deleting tags

2006-03-28 Thread jonasmg
Kent Johnson writes: 

> [EMAIL PROTECTED] wrote:
>> Is possible deleting all tags from a text and how?  
>> 
>> i.e.:  
>> 
>> s='foo bar;
>> foo2 > title="...">bar2'  
>> 
>> so, I would get only: foo bar, foo2, bar2
> 
> How about this? 
> 
> In [1]: import BeautifulSoup 
> 
> In [2]: s=BeautifulSoup.BeautifulSoup('''foo 
> bar;
>...: foo2  title="...">bar2''') 
> 
> In [4]: ' '.join(i.string for i in s.fetch() if i.string)
> Out[4]: 'foo bar foo2 bar2' 
> 
> 
> Here are a couple of tag strippers that don't use BS:
> http://www.aminus.org/rbre/python/cleanhtml.py
> http://www.oluyede.org/blog/2006/02/13/html-stripper/ 
> 
> Kent 
> 

Another way (valid only for this case): 

: for i in s.fetch('a'): print i.string 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] BeautifulSoup - deleting tags

2006-03-28 Thread Kent Johnson
[EMAIL PROTECTED] wrote:
> Is possible deleting all tags from a text and how? 
> 
> i.e.: 
> 
> qwe='foo bar;
> foo2 bar2' 
> 
> so, I would get only: foo bar, foo2, bar2 

How about this?

In [1]: import BeautifulSoup

In [2]: s=BeautifulSoup.BeautifulSoup('''foo bar;
...: foo2 bar2''')

In [4]: ' '.join(i.string for i in s.fetch() if i.string)
Out[4]: 'foo bar foo2 bar2'


Here are a couple of tag strippers that don't use BS:
http://www.aminus.org/rbre/python/cleanhtml.py
http://www.oluyede.org/blog/2006/02/13/html-stripper/

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor