Reputation: 1817
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"
Can anyone point me in the right direction here? I clearly see that the array has divs that contain Month/Day so not sure what I'm doing wrong. Thanks in advance.
Upvotes: 0
Views: 174
Reputation: 12930
I think probably it's because the uniqueDatesBucket is list of list. try this.
for i in uniqueDatesBucket[0]:
uniqueMonthDay = i.find_all('div')
Upvotes: 1