Facebook
From john, 2 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 45
  1. from getpass import getpass
  2. from selenium import webdriver
  3. from selenium.webdriver.common.by import By
  4. from selenium.webdriver.support.ui import WebDriverWait
  5. from selenium.webdriver.support import expected_conditions as EC
  6. import time
  7.  
  8.  
  9. username = "ioangeor14"
  10. password = getpass("Enter yoyr Password")
  11.  
  12.  
  13. url_login = "https://egram.cm.ihu.gr/unistudent/"
  14.  
  15. options = webdriver.ChromeOptions()
  16. options.add_experimental_option("excludeSwitches",["enable-logging", "enable-automation"])
  17. driver = webdriver.Chrome(options=options, executable_path=r"C:\\Temp\\chromedriver")
  18. driver.get(url_login)
  19.  
  20. driver.find_element_by_name("userName1").send_keys(username)
  21. driver.find_element_by_name("pwd").send_keys(password)
  22. driver.find_element_by_name("submit1").click()
  23.  
  24. driver.get("https://egram.cm.ihu.gr/unistudent/studentMain.asp")
  25.  
  26. url_vathmoi = "https://egram.cm.ihu.gr/unistudent/stud_CResults.asp?studPg=1&mnuid=mnu3&"
  27.  
  28.  
  29. driver.get(url_vathmoi)
  30.  
  31.  
  32.  
  33.  
  34.  
  35. before_XPath = "//*[@id='mainTable']/tbody/tr[2]/td/table/tbody/tr[50"
  36. aftertd_XPath = "]/td["
  37. aftertr_XPath = "]"
  38.  
  39.  
  40. #before_XPath = "//*[@id='mainTable']/tbody/tr["
  41. #aftertd_XPath = "]/td["
  42. #aftertr_XPath = "]"
  43.  
  44.  
  45.  
  46. rows = len(driver.find_elements_by_xpath("//*[@id='mainTable']/tbody/tr"))
  47. print(rows)
  48. columns = len(driver.find_elements_by_xpath("//*[@id='mainTable']/tbody/tr[2]/td"))
  49. print(columns)
  50.  
  51. for t_row in range(2, (rows + 1)):
  52.   for t_column in range(1, (columns + 1)):
  53.       FinalXPath = before_XPath + aftertd_XPath + str(t_column) + aftertr_XPath
  54.       cell_text = driver.find_element_by_xpath(FinalXPath).text
  55.       with open("VATHMOI.txt", "w", encoding="utf-8") as f:
  56.           f.write(cell_text)
  57.       driver.close()
  58.      
  59.      
  60.  
  61. #driver.quit()
  62. #while (driver.find_element(By.XPATH, "/html/body/table/tbody/tr[4]/td[2]/table/tbody/tr/td[1]/span[1]")):
  63. #       time.sleep(5)
  64. #       driver.get(url_vathmoi)
  65.