Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > BeautifulSoup problem

Reply
Thread Tools

BeautifulSoup problem

 
 
placid
Guest
Posts: n/a
 
      10-20-2006
Hi all,

Just wondering if anyone knows how to get the text between the tags of
the following Tag object?

<span class="nametext">Hello</span>

Cheers

 
Reply With Quote
 
 
 
 
Marc 'BlackJack' Rintsch
Guest
Posts: n/a
 
      10-20-2006
In <(E-Mail Removed) .com>, placid wrote:

> Hi all,
>
> Just wondering if anyone knows how to get the text between the tags of
> the following Tag object?
>
> <span class="nametext">Hello</span>


Are you looking for a way to search for tag *and* attributes? What about
this::

In [12]: soup.find('span', {'class': 'nametext'}).contents
Out[12]: [u'Hello']

Ciao,
Marc 'BlackJack' Rintsch
 
Reply With Quote
 
 
 
 
placid
Guest
Posts: n/a
 
      10-20-2006

Marc 'BlackJack' Rintsch wrote:
> In <(E-Mail Removed) .com>, placid wrote:
>
> > Hi all,
> >
> > Just wondering if anyone knows how to get the text between the tags of
> > the following Tag object?
> >
> > <span class="nametext">Hello</span>

>
> Are you looking for a way to search for tag *and* attributes? What about
> this::
>
> In [12]: soup.find('span', {'class': 'nametext'}).contents
> Out[12]: [u'Hello']


No this wasnt what i was looking for because i didnt know you could do
this. Thanks for that, this is better.

Cheers

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
encoding problem with BeautifulSoup - problem when writing parsedtext to file Greg Python 9 10-08-2011 03:30 PM
PAMIE and beautifulsoup problem elca Python 0 10-23-2009 06:03 AM
BeautifulSoup and Problem Tables academicedgar@gmail.com Python 2 09-22-2008 02:30 AM
BeautifulSoup Steve Young Python 4 08-20-2005 06:47 AM
HTML purifier using BeautifulSoup? Dan Stromberg Python 1 01-07-2005 06:10 PM



Advertisments