BeautifulSoup problem

Discussion in 'Python' started by placid, Oct 20, 2006.

  1. placid

    placid Guest

    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
     
    placid, Oct 20, 2006
    #1
    1. Advertising

  2. In <>, 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
     
    Marc 'BlackJack' Rintsch, Oct 20, 2006
    #2
    1. Advertising

  3. placid

    placid Guest

    Marc 'BlackJack' Rintsch wrote:
    > In <>, 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
     
    placid, Oct 20, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dan Stromberg

    HTML purifier using BeautifulSoup?

    Dan Stromberg, Dec 21, 2004, in forum: Python
    Replies:
    1
    Views:
    392
    Jonathan Clark
    Jan 7, 2005
  2. Replies:
    2
    Views:
    659
    clurks
    Sep 22, 2008
  3. elca
    Replies:
    0
    Views:
    322
  4. Greg
    Replies:
    9
    Views:
    820
    Nobody
    Oct 8, 2011
  5. Replies:
    5
    Views:
    75
    Peter Otten
    Dec 16, 2013
Loading...

Share This Page