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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:35:06+00:00 2026-06-15T23:35:06+00:00

i am trying to parse an HTML document, but bs4 fail to parse attribute

  • 0

i am trying to parse an HTML document, but bs4 fail to parse attribute in a specific tag:

<select class="inputNormal" id="TipoImmobileDaNonImportare" name="TipoImmobileDaNonImportare" style="width:100%">
            <option value=""></option>
            <option value="unità immobiliare urbana">unità immobiliare urbana</option>            
            <option value="particella terreni">particella terreni</option>
</select>

when i print, the error

AttributeError: 'tuple' object has no attribute 'items'`
the tag and attribute i print:`select: (u'style', u'class', u'name')`
instead of (for example):  `input: {u'type': u'hidden', u'name': u'Immobile_Note', u'value': u'Ubicazione occupazione', u'id': u'Immobile_Note'}`

UPDATE:
if i try soup.find_all( attrs= {'id' : 'somevalue' } ) it fail because try access all attributes of tree!

If i try:

s = BeautifulSoup( """<select class="inputNormal" id="TipoImmobileDaNonImportare" name="TipoImmobileDaNonImportare" style="width:100%">
<option value=""></option>
<option value="unità immobiliare urbana">unità immobiliare urbana</option>
<option value="particella terreni">particella terreni</option>
</select>""")

The parser detect it correctly:

select: {'id': 'TipoImmobileDaNonImportare', 'style': 'width:100%', 'class': ['inputNormal'], 'name': 'TipoImmobileDaNonImportare'}

i try to parse it with lxml parser and html5lib parser, but the result is the same.

Thanks for any replies.

EDIT:
thanks to Amanda, but there was an error in my code, i try to store in tag.attrs a touple object because this code is porting from bs3 to bs4!
Thanks.

  • 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-15T23:35:07+00:00Added an answer on June 15, 2026 at 11:35 pm

    I’m not entirely sure what you’re trying to access with Beautiful Soup here, but if you want to get at the attributes for the select or the options, you can do something like:

    html = """<select class="inputNormal" id="TipoImmobileDaNonImportare" name="TipoImmobileDaNonImportare" style="width:100%">
            <option value=""></option>
            <option value="unità immobiliare urbana">unità immobiliare urbana</option>
            <option value="particella terreni">particella terreni</option></select>"""
    
    soup = BeautifulSoup(html)
    

    You can show the attributes of the first “select” with:

    print soup.find('select').attrs
    

    Or show the attributes of all the options with:

    for option in soup.find_all('option'):
        print option.attrs
    

    Or, if you’re looking for the names of available items, use:

    for option in soup.find_all('option'):
        print option.text
    

    or if you want the option value rather than the displayed text, use:

    for option in soup.find_all('option'):
        print option['value']
    

    If that doesn’t help, maybe you could give an example of the output you’re expecting

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to parse an HTML document and extract some elements (any links to text
I am currently trying to parse an HTML document to retrieve all of the
I am trying to parse a string of HTML tag attributes in php. There
I'm trying to parse an html document with Jsoup to get all heading tags.
I'm trying to parse an HTML document for a web indexing program. To do
I am trying to parse a HTML document with help of DOM Xpath I
I'm new to lxml and python. I'm trying to parse an html document. When
I'm trying to parse a really simple HTML document with some xpath. There are
I am trying to parse an html page with BeautifulSoup, but it appears that
I am trying to parse html using BeautifulSoup to try and extract the webpage

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.