from getpass import getpass from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import time username = "ioangeor14" password = getpass("Enter yoyr Password") url_login = "https://egram.cm.ihu.gr/unistudent/" options = webdriver.ChromeOptions() options.add_experimental_option("excludeSwitches",["enable-logging", "enable-automation"]) driver = webdriver.Chrome(options=options, executable_path=r"C:\\Temp\\chromedriver") driver.get(url_login) driver.find_element_by_name("userName1").send_keys(username) driver.find_element_by_name("pwd").send_keys(password) driver.find_element_by_name("submit1").click() driver.get("https://egram.cm.ihu.gr/unistudent/studentMain.asp") url_vathmoi = "https://egram.cm.ihu.gr/unistudent/stud_CResults.asp?studPg=1&mnuid=mnu3&" driver.get(url_vathmoi) before_XPath = "//*[@id='mainTable']/tbody/tr[2]/td/table/tbody/tr[50" aftertd_XPath = "]/td[" aftertr_XPath = "]" #before_XPath = "//*[@id='mainTable']/tbody/tr[" #aftertd_XPath = "]/td[" #aftertr_XPath = "]" rows = len(driver.find_elements_by_xpath("//*[@id='mainTable']/tbody/tr")) print(rows) columns = len(driver.find_elements_by_xpath("//*[@id='mainTable']/tbody/tr[2]/td")) print(columns) for t_row in range(2, (rows + 1)): for t_column in range(1, (columns + 1)): FinalXPath = before_XPath + aftertd_XPath + str(t_column) + aftertr_XPath cell_text = driver.find_element_by_xpath(FinalXPath).text with open("VATHMOI.txt", "w", encoding="utf-8") as f: f.write(cell_text) driver.close() #driver.quit() #while (driver.find_element(By.XPATH, "/html/body/table/tbody/tr[4]/td[2]/table/tbody/tr/td[1]/span[1]")): # time.sleep(5) # driver.get(url_vathmoi)