Reputation: 1
I'm new to python and beautifulsoup, I'm sorry if this is a stupid question. I was trying to create a webscraper that takes the name of an inputted country and finds its money supply from the following website (https://tradingeconomics.com/country-list/money-supply-m2). Whenever I try to find all the a tags it keeps giving me this error:
"AttributeError: ResultSet object has no attribute 'find_all'.
You're probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()? "
Whenever I remove the .find_all(a) it works.
Here is my code:
from bs4 import BeautifulSoup
import requests
url4='https://tradingeconomics.com/country-list/money-supply-m2'
def run_scraper():
print('running')
country=input('Please input the name of the country: ')
content4=requests.get(url4).text
soup4=BeautifulSoup(content4,'html.parser')
t=country.title()
table=soup4.find('table',{'class':'table table-hover'})
for tr in table.find_all('tr'):
co=tr.find_all('td').find_all('a')
print(co)
run_scraper()
Can someone tell me what I am doing wrong?
Thank you.
Upvotes: 0
Views: 122
Reputation: 81594
find_all
returns (essentially) a list. A list does not have a find_all
method.
You need to iterate over all td
elements, just like you already iterate over all the tr
elements:
for tr in table.find_all('tr'):
for td in tr.find_all('td'):
co = td.find_all('a')
print(co)
Upvotes: 3