Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7785737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:18:14+00:00 2026-06-01T20:18:14+00:00

From this html source: <div class=category_link> Category: <a href=/category/personal>Personal</a> </div> I wish to extract

  • 0

From this html source:

<div class="category_link">
  Category:
  <a href="/category/personal">Personal</a>
</div>

I wish to extract the text Category:

Here are my attempts using Python/BeautifulSoup (with output as comment – after the #)

parsed = BeautifulSoup(sample_html)
parsed_div = parsed.findAll('div')[0]
parsed_div.firstText() # <a href="/category/personal">Personal</a>
parsed_div.first() # <a href="/category/personal">Personal</a>
parsed_div.findAll()[0] # <a href="/category/personal">Personal</a>

I’d expect a “text node” to be available as the first child. Any suggestions on how I can solve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:18:15+00:00Added an answer on June 1, 2026 at 8:18 pm

    I’m fairly sure the following should do what you want

    parsed.find('a').previousSibling # or something like that
    

    That would return a NavigableString instance which is pretty much the same
    thing as a unicode instance, but you may call unicode on that to get a
    unicode object.

    I’ll see if I can test this out and let you know.

    EDIT: I just confirmed that it works:

    >>> from BeautifulSoup import BeautifulSoup
    >>> soup = BeautifulSoup('<div class=a>Category: <a href="/">a link</a></div>')
    >>> soup.find('a')
    <a href="/">a link</a>
    >>> soup.find('a').previousSibling
    u'Category: '
    >>> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to extract items from this sample html, more specificly, i would
This is the HTML part: div id=messages> <div class=messages> <?php if(isset ($unread)) { ?>
My code is as below. Html Portion <div id=div_video> <div class=div_vol> <a href=# onclick=sound_adjustment()><img
How can I the HTML string <br> from this HTML FORM pass to the
From this site: http://www.toymaker.info/Games/html/vertex_shaders.html We have the following code snippet: // transformations provided by
from this site there is header compress.h http://www.fredosaurus.com/notes-cpp/examples/compress/compress.html i am using visual c++ 2010
I have installed android sdk from this link http://developer.android.com/sdk/index.html.(installer_r18-windows .... android app is working
I've placed panel from this example http://docs.sencha.com/ext-js/4-0/#!/example/dd/dnd_grid_to_grid.html to Ext.window.Window and got an issue: proxy
I'm trying to parse a html doc using some code I found from this
I have a HTML table as follows. I want retrieve row values from this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.