I am trying to save data from multiple website to csv using selenium
driver = webdriver.Chrome(executable_path='C:/Users/trive/Downloads/chromedriver_win32/chromedriver.exe')
templist = []
for i in range(len(data)):
driver.get(data._get_value(i,'URL'))
try:
title= driver.find_element(By.CLASS_NAME, "amp-wp-title").text
content= driver.find_element(By.CLASS_NAME, "amp-wp-article-content").text
Table_dict={ 'Title': title,
'Content':content}
templist.append(Table_dict)
df = pd.DataFrame(templist)
except NoSuchElementException:
continue
# saving the dataframe to a csv
df.to_csv('S:/DEADPOOL/black coffr assignment/table.csv')
driver.close()
I am getting the following error message:
NameError Traceback (most recent call last)
<ipython-input-18-8534ce45b80d> in <module>
---> 28 print(df)
NameError: name 'df' is not defined
I think it is to do with df only existing in the for loop and not outside but i don't know how to solve this.