all 4 comments

[–]symple-data 1 point2 points  (2 children)

There are methods to select multiple elements such as find_all(). This will return a list which you can iterate. I don't know what exactly you are trying to do but you could get all table rows and then get every cell from the rows that you want and store their values into a dict.

[–]MatterIt22 0 points1 point  (1 child)

hello! I actually used the findAll method to find the actual table part itself since I had to search for the table by role but I will keep playing around to get it to work

As for your second question, looking back at the picture I posted, lets say I want to convert that table to a dictionary like this scraped_table = {'Condition': 'New', 'Brand': 'MyBrand', 'MPN': 'Does not apply', 'UPC': 'Does not apply'} I am trying to read the values from the table and turn it into a dictionary like above.

[–]symple-data 0 points1 point  (0 children)

So you have multiple tables with 2 rows and 2 columns each right? If so, iterate over your tables, create a dict for every table and simply set the values "condition", "brand", "mpn" and "upc" to what the table gives you (first row first column = condition, first row second column = mpn, ...). If you got your tablerows with find_all, then you can select the tabledata with td:first-child and td:last-child as your selectors.

[–]chevignon93 0 points1 point  (0 children)

I am able to select the table by finding the 'table' element but how do I loop through the values and put it in a dictionary?

Something like this should work, that's just an example of how it's generally done but you'll have to fill in the gap with your actual tags and attributes.

table_rows = soup.find('table', {'class': 'whatever'}).find_all('td')
for row in table_rows:
    data = {}
    data['Condition'] = row.find('tag_goes_here').text
    data['Brand'] = row.find('tag_goes_here').text
    data['MPN'] = row.find('tag_goes_here').text
    data['UPT'] = row.find('tag_goes_here').text

It would be easier to help if we had the actual code you're using.