im trying to learn python webscraping tried the below code but facing the below error.Can someone please help with the correct approach
url = "https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-PY0220EN-SkillsNetwork/labs/project/revenue.htm"
html_data = requests.get(url).text
tesla_revenue = pd.DataFrame(columns = ['Date','Revenue'])
soup = BeautifulSoup(html_data,'html.parser')
for row in soup.find("tbody")[1].find_all("tr"):
col = row.find_all("td")
Date = col[0].text
Revenue = col[1].text
tesla_revenue = pd.concat([tesla_revenue,pd.DataFrame({"Date":[Date],"Revenue":[Revenue]})],ignore_index = True)
tesla_revenue
error:
KeyError Traceback (most recent call last)
Cell In[30], line 5
3 tesla_revenue = pd.DataFrame(columns = ['Date','Revenue'])
4 soup = BeautifulSoup(html_data,'html.parser')
----> 5 for row in soup.find("tbody")[1].find_all("tr"):
6 col = row.find_all("td")
7 Date = col[0].text
File /opt/conda/lib/python3.11/site-packages/bs4/element.py:1573, in Tag.__getitem__(self, key)
1570 def __getitem__(self, key):
1571 """tag[key] returns the value of the 'key' attribute for the Tag,
1572 and throws an exception if it's not there."""
-> 1573 return self.attrs[key]
KeyError: 1