BeautifulSoup to get string inner 'p' and 'a' tags

2006-07-24 Thread GinTon
I'm trying to get the 'FOO' string but the problem is that inner 'P' tag there is another tag, 'a'. So: from BeautifulSoup import BeautifulSoup s = 'td width=88% valign=TOP p class=contentBodyFOO a name=f/a /p/td' tree = BeautifulSoup(s) print tree.first('p') p class=contentBodyFOO a

Re: BeautifulSoup to get string inner 'p' and 'a' tags

2006-07-24 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], GinTon wrote: I'm trying to get the 'FOO' string but the problem is that inner 'P' tag there is another tag, 'a'. So: from BeautifulSoup import BeautifulSoup s = 'td width=88% valign=TOP p class=contentBodyFOO a name=f/a /p/td' tree = BeautifulSoup(s) print

Re: BeautifulSoup to get string inner 'p' and 'a' tags

2006-07-24 Thread GinTon
Marc 'BlackJack' Rintsch wrote: In [53]: print tree.first('p').contents[0] FOO Thanks! I was going to crazy with this. -- http://mail.python.org/mailman/listinfo/python-list

Re: BeautifulSoup to get string inner 'p' and 'a' tags

2006-07-24 Thread Nick Vatamaniuc
Quick-n-dirty way: After you get your whole p string: p class=contentBodyFOO a name=f/a /p Remove any tags delimited by '' and '' with a regex. In your short example you _don't_ show that there might be something between the a and /a tags so I assume there won't be anything or if there would be