pythonparsingweb-scrapingbeautifulsoup

ResultSet object has no attribute '%s' when parsing array in BeautifulSoup


I'm using Beautiful Soup to parse some HTML. Here's the code:

//Build container for 'dates' divs
uniqueDatesBucket = []
for i in soupBucket:
   uniqueDate = i.find_all('div', {'class': 'event-b58f7990'})
   uniqueDatesBucket.append(uniqueDate)    

print uniqueDatesBucket

uniqueDatesBucket, when printed, works as expected and produces the following (an abbreviated version below):

[[<div class="event-b58f7990"><div class="event-ad736269">JAN</div><div class="event-d7a00339">06</div></div>, <div class="event-b58f7990"><div class="event-ad736269">JAN</div><div class="event-d7a00339">06</div></div>]]

I want to parse Month/Day from the above array.

uniqueMonth = []
uniqueDay = []

for i in uniqueDatesBucket:
    uniqueMonthDay = i.find_all('div')

However, this fails and I get the following error:

"ResultSet object has no attribute '%s'. You're probably treating a list of items like a single item"

What can I try next? I clearly see that the array has divs that contain Month/Day so I'm not sure what I'm doing wrong.


Solution

  • I think probably it's because the uniqueDatesBucket is list of list. try this.

    for i in uniqueDatesBucket[0]:
        uniqueMonthDay = i.find_all('div')