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

  • Home
  • SEARCH
  • 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 898485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:03:03+00:00 2026-05-15T15:03:03+00:00

i am parsing some html form with Beautiful soup. Basically i´ve around 60 input

  • 0

i am parsing some html form with Beautiful soup. Basically i´ve around 60 input fields mostly radio buttons and checkboxes. So far this works with the following code:

from BeautifulSoup import BeautifulSoup
x = open('myfile.html','r').read()
out = open('outfile.csv','w')
soup = BeautifulSoup(x)
values = soup.findAll('input',checked="checked")
# echoes some output like ('name',1) and ('value',4)

for cell in values:
# the following line is my problem! 
    statement = cell.attrs[0][1] + ';' + cell.attrs[1][1] + ';\r'
    out.write(statement)

out.close()
x.close()

As indicating in the code my problem ist where the attributes are selected, because the HTML template is ugly, mixing up the sequence of arguments that belong to a input field. I am interested in name=”somenumber” value=”someothernumber” . Unfortunately my attrs[1] approach does not work, since name and value do not occur in the same sequence in my html.

Is there any way to access the resulting BeautifulSoup list associatively?

Thx in advance for any suggestions!

  • 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-05-15T15:03:04+00:00Added an answer on May 15, 2026 at 3:03 pm

    My suggestion is to make values a dict. If soup.findAll returns a list of tuples as you seem to imply, then it’s as simple as:

    values = dict(soup.findAll('input',checked="checked"))
    

    After that you can simply refer to the values by their attribute name, like what Peter said.

    Of course, if soup.findAll doesn’t return a list of tuples as you’ve implied, or if your problem is that the tuples themselves are being returned in some weird way (such that instead of (‘name’, 1) it would be (1, ‘name’)), then it could be a bit more complicated.

    On the other hand, if soup.findAll returns one of a certain set of data types (dict or list of dicts, namedtuple or list of namedtuples), then you’ll actually be better off because you won’t have to do any conversion in the first place.

    …Yeah, after checking the BeautifulSoup documentation, it seems that findAll returns an object that can be treated like a list of dicts, so you can just do as Peter says.

    http://www.crummy.com/software/BeautifulSoup/documentation.html#The%20attributes%20of%20Tags

    Oh yeah, if you want to enumerate through the attributes, just do something like this:

    for cell in values:
        for attribute in cell:
            out.write(attribute + ';' + str(cell[attribute]) + ';\r')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a page,say abc.html, that is having a small form with some fields.
Trying to print out some html forms but I get a parsing syntax error.
I'm having difficulty parsing some JSON data returned from my server using jQuery.ajax() To
I am parsing some XML something like this: <root> <some_gunk/> <dupe_node> ... stuff I
I'm just in the process of parsing some text and can't remember what the
I've been parsing through some log files and I've found that some of the
What are some good tools for getting a quick start for parsing and analyzing
I'm doing some Objective-C programming that involves parsing an NSXmlDocument and populating an objects
I'm parsing big XML file with XPathExpression selection for some nodes existing at various
I am involved in a venture that will port some communications, parsing, data handling

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.