Issue
I am trying to get some data from a webpage, but I keep getting error. Tried searching google, but I can not seem to find a good solution.
url = "https://coinmarketcap.com/currencies/bitcoin/historical-data/"
content = requests.get(url).content
soup = BeautifulSoup(content,'html.parser')
table = soup.find('table', {'class': 'table'})
print(table)
data = [[td.text.strip() for td in tr.findChildren('td')]
for tr in table.findChildren('tr')]
output:
Traceback (most recent call last):
File "C:/Users/Ejer/PycharmProjects/pythonProject/stock_analysis.py", line 13, in <module>
for tr in table.findChildren('tr')]
AttributeError: 'NoneType' object has no attribute 'findChildren'
Solution
you need to put the class of the table has, instead of just table and in your case it has cmc-table
table = soup.find('table', {'class': 'cmc-table'}
Try this it gets the table
Answered By - jedimasterbot
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.