Dear Concern: I am not expert in programming. I am a self learner. I have developed the following code which works fine in my laptop but I need to run the code based on scheduler. So, I made a free account of storage (500MB) in "pythonanywhere" and put the file including chrome.exe in two locations. 1) /home/srabon2021/.virtualenvs/ & 2) /home/srabon2021/.local/bin/, but the code does not run. It says:
"Traceback (most recent call last): File "/home/srabon2021/.local/bin/Market_Depth_04.07.2021.py", line 14, in <module> driver = webdriver.Chrome(PATH, options=chrome_options) File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in init self.service.start() File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 72, in start self.process = subprocess.Popen(cmd, env=self.env, File "/usr/local/lib/python3.9/subprocess.py", line 951, in init self._execute_child(args, executable, preexec_fn, close_fds, File "/usr/local/lib/python3.9/subprocess.py", line 1696, in _execute_child and os.path.dirname(executable) File "/usr/local/lib/python3.9/posixpath.py", line 152, in dirname p = os.fspath(p) TypeError: expected str, bytes or os.PathLike object, not NoneType
My code is below:
import openpyxl import datetime import time from shutil import which from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By
chrome_options = webdriver.ChromeOptions()
Chrome is made headless
chrome_options.add_argument('--headless')
Path to chromedriver. Keep it in the folder where the file is located. For windows, change the / to \ and add .exe after chromedriver
PATH = which("chromedriver.exe") driver = webdriver.Chrome(PATH, options=chrome_options)
List of instruments
instrument = ['ACMELAB', 'ACTIVEFINE', 'AAMRANET', 'AAMRATECH', 'ABB1STMF', 'ABBANK', 'ACFL', 'ACI', 'ACIFORMULA'] driver.get("https://www.dsebd.org/mkt_depth_3.php") search = driver.find_element_by_name("inst") time.sleep(5) for x in instrument: BUY_PRICE = BUY_VOLUME = SELL_PRICE = SELL_VOLUME = 0 search.send_keys(x) search.send_keys(Keys.RETURN) time.sleep(2) buy_rows = len(driver.find_elements(By.XPATH, '//[@id="RightBody"]/div[2]/div/table/tbody/tr[2]/td[2]/table/tbody/tr/td[1]/table/tbody/tr'))-2 sell_rows = len(driver.find_elements(By.XPATH, '//[@id="RightBody"]/div[2]/div/table/tbody/tr[2]/td[2]/table/tbody/tr/td[2]/table/tbody/tr'))-2 if (buy_rows >= 1) and (sell_rows >= 1): BUY_PRICE = driver.find_element(By.XPATH, '//[@id="RightBody"]/div[2]/div/table/tbody/tr[2]/td[2]/table/tbody/tr/td[1]/table/tbody/tr[3]/td[1]/div') BUY_VOLUME = driver.find_element(By.XPATH, '//[@id="RightBody"]/div[2]/div/table/tbody/tr[2]/td[2]/table/tbody/tr/td[1]/table/tbody/tr[3]/td[2]/div') SELL_PRICE = driver.find_element(By.XPATH, '//[@id="RightBody"]/div[2]/div/table/tbody/tr[2]/td[2]/table/tbody/tr/td[2]/table/tbody/tr[3]/td[1]/div') SELL_VOLUME = driver.find_element(By.XPATH, '//[@id="RightBody"]/div[2]/div/table/tbody/tr[2]/td[2]/table/tbody/tr/td[2]/table/tbody/tr[3]/td[2]/div') print(x, BUY_PRICE.text, BUY_VOLUME.text, SELL_PRICE.text, SELL_VOLUME.text) elif (buy_rows >= 1) and (sell_rows == 0): BUY_PRICE = driver.find_element(By.XPATH, '//[@id="RightBody"]/div[2]/div/table/tbody/tr[2]/td[2]/table/tbody/tr/td[1]/table/tbody/tr[3]/td[1]/div') BUY_VOLUME = driver.find_element(By.XPATH, '//[@id="RightBody"]/div[2]/div/table/tbody/tr[2]/td[2]/table/tbody/tr/td[1]/table/tbody/tr[3]/td[2]/div') print(x, BUY_PRICE.text, BUY_VOLUME.text, "Blank", "Blank") elif (buy_rows == 0) and (sell_rows >= 1): SELL_PRICE = driver.find_element(By.XPATH, '//[@id="RightBody"]/div[2]/div/table/tbody/tr[2]/td[2]/table/tbody/tr/td[2]/table/tbody/tr[3]/td[1]/div') SELL_VOLUME = driver.find_element(By.XPATH, '//[@id="RightBody"]/div[2]/div/table/tbody/tr[2]/td[2]/table/tbody/tr/td[2]/table/tbody/tr[3]/td[2]/div') print(x, "Blank", "Blank", SELL_PRICE.text, SELL_VOLUME.text) else: print(x, "Blank", "Blank", "Blank", "Blank")
# Writing to Excel file
book = openpyxl.load_workbook("E:\moin.xlsx")
ws = book["Sheet1"]
r = ws.max_row + 1
ws.cell(row=r, column=1, value=datetime.date(
int(time.strftime("%Y")),
int(time.strftime("%m")),
int(time.strftime("%d"))
))
ws.cell(row=r, column=2, value=time.strftime("%X"))
ws.cell(row=r, column=3, value=x)
ws.cell(row=r, column=4, value=float(BUY_PRICE.text) if BUY_PRICE else 0)
ws.cell(row=r, column=5, value=float(BUY_VOLUME.text) if BUY_VOLUME else 0)
ws.cell(row=r, column=6, value=float(SELL_PRICE.text) if SELL_PRICE else 0)
ws.cell(row=r, column=7, value=float(SELL_VOLUME.text) if SELL_VOLUME else 0)
book.save('E:\moin.xlsx')
driver.close()
Can anybody please help me. It would be a great help for me.
Thank you.