I have already imported the data from the web page using request and beautifulsoup. Still, I wanted to export the results to csv file. Is it possible?
from bs4 import BeautifulSoup
import urllib.request
import csv
url = 'https://www.fundamentus.com.br/resultado.php'
r = urllib.request.urlopen(url).read()
soup = BeautifulSoup(r, 'lxml')
data = []
table = soup.find('table', { "id" : "resultado" })
table_body = table.find('tbody')
rows = table_body.find_all('tr')
for row in rows:
cols = row.find_all('td')
cols = [ele.text.strip() for ele in cols]
data.append([ele for ele in cols if ele])
print(data)