I have this little part of a code that I am not understanding why I am getting double backslashes when I join the both paths together.
Here is the code
import time
import os
from selenium import webdriver
start = time.time()
sleep_time = 30
universe_data_site = 'http://www.csidata.com/?page_id=10'
database = "E:\\Stock Database\\Historical Data\\Historical Stock List\\"
chrome_options = webdriver.ChromeOptions()
prefs = {'download.default_directory': database}
chrome_options.add_experimental_option(name='prefs', value= prefs)
stocks = webdriver.Chrome(r"E:\Python Programs\chromedriver", chrome_options = chrome_options)
#Website
stocks.get(universe_data_site)
#Navigate Web Page
stocks.find_element_by_css_selector('#ui-id-4').click()
stocks.find_element_by_css_selector('#stocks >a.blue_button.factbutton').click()
stocks.find_element_by_css_selector('body > a:nth-child(3)').click()
#Download and renaiming of File
filename = 'AllStocks.csv'
#removes existing file if already exists
if os.path.exists(r"%s%s"%(database,filename)) is True:
os.remove(r"%s%s"%(database,filename))
os.rename(r"%s"%database+"stockfactsheet.csv",r"%s%s"%(database,filename))
else:
os.rename(r"%s"%database+"stockfactsheet.csv",r"%s%s"%(database,filename))
time.sleep(sleep_time)
stocks.close()
What am I missing? I keep getting this error
FileNotFoundError Traceback (most recent call last)
<ipython-input-24-194be27799ad> in <module>()
17 os.rename(r"%s"%database+"stockfactsheet.csv",r"%s%s"%(database,filename))
18 else:
---> 19 os.rename(r"%s"%database+"stockfactsheet.csv",r"%s%s"%(database,filename))
20
21 time.sleep(sleep_time)
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'E:\\Stock Database\\Historical Data\\Historical Stock List\\stockfactsheet.csv' -> 'E:\\Stock Database\\Historical Data\\Historical Stock List\\AllStocks.csv'