I just started learning how to scrape websites a few hours ago and it seems that I've hit a roadblock regarding "FindAll"
My code:
soup = BeautifulSoup(html_text, 'lxml')
goals = soup.findAll('tr', attrs={'style': 'background-color: #262101'})
secret_goals = goals.findAll('href').text
print(secret_goals)
It always returns an error of:
AttributeError: ResultSet object has no attribute 'findAll'. You're probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()?
Is there any solutions that I can do? Or am I doing something wrong?
The findAll
method returns a list of tag elements: you have to loop over them and extract what you need.
goals = soup.find_all('tr', attrs={'style': 'background-color: #262101'})
result = []
for goal in goals:
result.append(goal.get('href'))
...
Also, I think camel case methods are deprecated, so use snake case instead. I don't think it matters though.