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 146017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:31:35+00:00 2026-05-11T08:31:35+00:00

This is the HTML I have: p_tags = ”'<p class=foo-body> <font class=test-proof>Full name</font> Foobar<br

  • 0

This is the HTML I have:

p_tags = '''<p class='foo-body'>   <font class='test-proof'>Full name</font> Foobar<br />   <font class='test-proof'>Born</font> July 7, 1923, foo, bar<br />   <font class='test-proof'>Current age</font> 27 years 226 days<br />   <font class='test-proof'>Major teams</font> <span style='white-space: nowrap'>Japan,</span> <span style='white-space: nowrap'>Jakarta,</span> <span style='white-space: nowrap'>bazz,</span> <span style='white-space: nowrap'>foo,</span> <span style='white-space: nowrap'>foobazz</span><br />   <font class='test-proof'>Also</font> bar<br />   <font class='test-proof'>foo style</font> hand <br />   <font class='test-proof'>bar style</font> ball<br />   <font class='test-proof'>foo position</font> bak<br />   <br class='bar' /> </p>''' 

This is my Python code, using Beautiful Soup:

def get_info(p_tags):     '''Returns brief information.'''      head_list = []     detail_list = []     # This works fine     for head in p_tags.findAll('font', 'test-proof'):         head_list.append(head.contents[0])      # Some problem with this?     for index in xrange(2, 30, 4):         detail_list.append(p_tags.contents[index])       return dict([(l, detail_list[head_list.index(l)]) for l in head_list]) 

I get the proper head_list from the HTML but the detail_list is not working.

 head_list = [u'Full name',  u'Born',  u'Current age',  u'Major teams',  u'Also',  u'foo style',  u'bar style',  u'foo position'] 

I wanted something like this

 {   'Full name': 'Foobar',    'Born': 'July 7, 1923, foo, bar',    'Current age': '78 years 226 days',    'Major teams': 'Japan, Jakarta, bazz, foo, foobazz',    'Also': 'bar',    'foo style': 'hand',    'bar style': 'ball',    'foo position': 'bak' } 

Any help would be appreciable. Thanks in advance.

  • 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. 2026-05-11T08:31:36+00:00Added an answer on May 11, 2026 at 8:31 am

    Sorry for the unnecessarily complex code, I badly need a big dose of caffeine 😉

    import re  str = '''<p class='foo-body'>   <font class='test-proof'>Full name</font> Foobar<br />   <font class='test-proof'>Born</font> July 7, 1923, foo, bar<br />   <font class='test-proof'>Current age</font> 27 years 226 days<br />   <font class='test-proof'>Major teams</font> <span style='white-space: nowrap'>Japan,</span> <span style='white-space: nowrap'>Jakarta,</span> <span style='white-space: nowrap'>bazz,</span> <span style='white-space: nowrap'>foo,</span> <span style='white-space: nowrap'>foobazz</span><br />   <font class='test-proof'>Also</font> bar<br />   <font class='test-proof'>foo style</font> hand <br />   <font class='test-proof'>bar style</font> ball<br />   <font class='test-proof'>foo position</font> bak<br />   <br class='bar' /> </p>'''  R_EXTRACT_DATA = re.compile('<font\s[^>]*>[\s]*(.*?)[\s]*</font>[\s]*(.*?)[\s]*<br />', re.IGNORECASE) R_STRIP_TAGS = re.compile('<span\s[^>]*>|</span>', re.IGNORECASE)  def strip_tags(str):     '''Strip un-necessary <span> tags     '''     return R_STRIP_TAGS.sub('', str)  def get_info(str):     '''Extract useful info from the given string     '''     data = R_EXTRACT_DATA.findall(str)     data_dict = {}      for x in [(x[0], strip_tags(x[1])) for x in data]:         data_dict[x[0]] = x[1]      return data_dict  print get_info(str) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just normalized the font size with this: html, body, div, span, applet,
So i have this in Strings.xml: <string name=sixpackInfo> <html><body><p>Lorem ipsum dolor sit amet, consectetur
I have got this html: <div id=myDiv> <p class=readMore></p> <p class=readMore></p> <p class=readMore></p> </div>
I have html that looks like this with several items <div class=item> <p class=price>$388.00</p>
i have a html text like this: <div id=content> <p>para1</p> <p>para2</p> <p>para3</p> <p class=break>para4</p>
<p title=The test paragraph>This is a sample of some <b>HTML you might<br>have</b> in your
I have this: HTML: <p class=Link><a href=...>Test1</a></p> <p class=Link><a href=...>Test2</a></p> <p class=Link><a href=...>Test3</a></p> jQuery
I have this piece of HTML: <div class=embed> <iframe width=300 height=200 frameborder=0 allowfullscreen= src=http://www.youtube.com/embed/123456></iframe>
I have this HTML input: <font size=5><p>some text</p> <p> another text</p></font> I'd like to
I'm wondering if this is possible. I have html like so: <p> <font face=Georgia>

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.