When I run the below code, a chrome window opens, the page loads and a CSV file downloads into my documents.
However, I want to download the CSV file into a python list.
When I try to print the initial download it shows 'None' and reading in csv.reader shows the following error message:
import csv
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
def getData()
driver = webdriver.Chrome()
driver.get(f"http://financials.morningstar.com/balance-sheet/bs.html?t=AAPL")
button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, "rf_export")))
data = button.click()
print(data)
data = csv.reader(button)
for row in data:
print(row)
return data
getData()
-------------
None
Traceback (most recent call last):
File "helpers.py", line 403, in <module>
newData2("AAPL")
File "helpers.py", line 397, in newData2
data = csv.reader(button)
TypeError: argument 1 must be an iterator