I'm trying to scrape the table in the following website but was not able to do it:
https://www.moneycontrol.com/financials/relianceindustries/ratiosVI/RI?classic=true#RI
import csv
from bs4 import BeautifulSoup
from urllib.request import urlopen
soup = BeautifulSoup(urlopen('https://www.moneycontrol.com/financials/relianceindustries/ratiosVI/RI?classic=true#RI'))
table = soup.find('table', attrs={ "class" : "table-horizontal-line"})
headers = [header.text for header in table.find_all('th')]
rows = []
for row in table.find_all('tr'):
rows.append([val.text.encode('utf8') for val in row.find_all('td')])
with open('output_file.csv', 'wb') as f:
writer = csv.writer(f)
writer.writerow(headers)
writer.writerows(row for row in rows if row)
something = table.find_all('tr')' on a separate line, then go into the loopfor row in something:` but that's my best guess without more information on whats wrong