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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:06:13+00:00 2026-06-02T19:06:13+00:00

Trying the following code doesn’t seem to work out for me quite as planned:

  • 0

Trying the following code doesn’t seem to work out for me quite as planned:
from beautifulsoup import BeautifulSoup

definition = """From encyclopedia:\n<i></i><p>Infobox Country<br>fullcountryname=Thailand  &#x0E23;&#x0E32;&#x0E0A;&#x0E2D;&#x0E32;&#x0E13;&#x0E32;&#x0E08;&#x0E31;&#x0E01;&#x0E23;&#x0E44;&#x0E17;&#x0E22;Raja-anachakra Thai <br>image_flag= Flag of Thailand.svg <br>image_coa= Coat of arms of Thailand.png <br>image_location= LocationThailand.png <br>nationalmotto= none <br>nationalsong= Phleng Chat <br>nationalflower= n/a <br>nationalanimal= n/a <br>officiallanguages= Thai (<r><i>Thai language</i></r>) <br>populationtotal= 65,444,371 <br>populationrank= 19 <br>populationdensity= 127 <br>countrycapital= <r>Bangkok</r> <br>countrylargestcity= <r>Bangkok</r> <br>areatotal= 514,000 <br>arearank= 49 <br>areawater= n/a <br>areawaterpercent= 0.4 <br>establishedin= <r>April 7</r>, <r>1782</r> <br>leadertitlename=    <br>currency= <r>Baht</r> <br>utcoffset= +7 <br>dialingcode= 66 <br>internettld= .th<p><b>Thailand</b> is a <r>country</r> in Southeast <r>Asia</r>.  Its edges touch <r>Laos</r>, <r>Cambodia</r>, <r>Malaysia</r>, and <r>Myanmar</r> (which is also called Burma.) Thailand was called Siam until 1949."""

print BeautifulSoup(definition).find('p[1]').text

This does not return anything.. I’m sure it’s a syntax error with my use of BeautifulSoup, has anybody got any idea how I could simply get:

Infobox Country
fullcountryname=Thailand Raja-anachakra Thai 
image_flag= Flag of Thailand. svg 
image_coa= Coat of arms of Thailand. png 
image_location= LocationThailand. png 
nationalmotto= none 
nationalsong= Phleng Chat 
nationalflower= n/a 
nationalanimal= n/a 
officiallanguages= Thai (Thai language) 
populationtotal= 65,444,371 
populationrank= 19 
populationdensity= 127 
countrycapital= Bangkok 
countrylargestcity= Bangkok 
areatotal= 514,000 
arearank= 49 
areawater= n/a 
areawaterpercent= 0. 4 
establishedin= April 7, 1782 
leadertitlename=  
currency= Baht 
utcoffset= +7 
dialingcode= 66 
internettld= . th

Thank you 🙂

EDIT: I would actually prefer if I could get the text between the word “Infobox” and the last

tag, so that I could use the script to parse live wikipedia pages.

  • 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-02T19:06:13+00:00Added an answer on June 2, 2026 at 7:06 pm

    You’re using XPath syntax, which Beautiful Soup doesn’t support. Lattyware’s answer is correct. As for the question in your edit, you can use Beautiful Soup 4’s .stripped_strings generator to get approximately what you want. Some example code:

    from bs4 import BeautifulSoup
    soup = BeautifulSoup(definition)
    
    import re
    infobox_start = re.compile("^Infobox") 
    
    start_at = soup.find(text=infobox_start)
    for string in start_at.parent.stripped_strings:
        print string
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following jquery code which doesn't work quite right when trying to
The following code doesn't work, but it best show what I'm trying to achieve
I'm trying the following code: Try ' DOESN'T WORK Throw 2 ' How do
I'm trying to understand why the following code using Scala Streams doesn't work: def
I'm trying to load my .mo translations using the following code, but it doesn't
I'm trying the following code http://code.google.com/apis/ajax/playground/#change_the_playing_video It works well when runned from the playground
I am trying out the following code inside a wordpress template: <?php //connect to
I was trying out the following code which actually saves the pdf file to
when I trying to run following code. var result = from c in db.brand
The following code doesn't compile for obvious reasons, namely that Foo is trying to

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.