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

The Archive Base Latest Questions

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

I’m trying to write my first parser with BeautifulSoup (BS4) and hitting a conceptual

  • 0

I’m trying to write my first parser with BeautifulSoup (BS4) and hitting a conceptual issue, I think. I haven’t done much with Python — I’m much better at PHP.

I can get BeautifulSoup to find the table I want, but when I try to step into the table and find all the rows, I get some variation on:

AttributeError: 'ResultSet' object has no attribute 'attr'

I tried walking through the sample code at How do I draw out specific data from an opened url in Python using urllib2? and got more or less the same error (note: if you want to try it you’ll need a working URL.)

Some of what I’m reading says that the issue is that the ResultSet is a list. How would I know that? If I do print type(table) it just tells me <class 'bs4.element.ResultSet'>

I can find text in the table with:

for row in table:
    text = ''.join(row.findAll(text=True))
    print text

but if I try to search for HTML with:

for row in table:
    text = ''.join(row.find_all('tr'))
    print text

It complains about expected string, Tag found So how do I wrangle this string (which is a string full of HTML) back into a beautifulsoup object that I can parse?

  • 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-13T01:02:38+00:00Added an answer on June 13, 2026 at 1:02 am

    BeautifulSoup data-types are bizarre to say the least. A lot of times they don’t give enough information to easily piece together the puzzle. I know your pain! Anyway…on to my answer…

    Its hard to provide a completely accurate example without seeing more of your code, or knowing the actual site you’re attempting to scrape, but I’ll do my best.

    The problem is your ''.join(). .findAll('tr') returns a list of elements of the BeautifulSoup datatype ‘tag’. Its how BS knows to find trs. Because of this, you’re passing the wrong datatype to your ''.join().

    You should code one more iteration. (I’m assuming there are td tags withing the trs)

    text_list = []
    for row in table:
        table_row = row('tr')
        for table_data in table_row:
            td = table_data('td')
            for td_contents in td:
                content = td_contents.contents[0]
                text_list.append(content)
    text = ' '.join(str(x) for x in text_list)
    

    This returns the entire table content into a single string. You can refine the value of text by simply changing the locations of text_list and text =.

    This probably looks like more code than is required, and that might be true, but I’ve found my scrapes to be much more thorough and accurate when I go about it this way.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to select an H1 element which is the second-child in its group

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.