close

1.前置作業

如果沒有Selenium的, 還是一樣先pip install selenium

然後到https://sites.google.com/a/chromium.org/chromedriver/downloads 下載chromedriver,

接著把它放在喜歡的資料夾, 網路上大家都放 C:\selenium_driver_chrome\chromedriver.exe 

2.程式碼

from selenium import webdriver
from time import sleep


driver = webdriver.Chrome(r"C:\selenium_driver_chrome\chromedriver.exe")

driver.implicitly_wait(10)
driver.maximize_window()

driver.get("https://www.cp.gov.tw/portal/Clogin.aspx?ReturnUrl=https%3A%2F%2Felearn.hrd.gov.tw%2Fegov_login.php")
sleep(1)

driver.find_element_by_xpath("//input[@name='ctl00$ContentPlaceHolder1$AccountPassword1$txt_account']").send_keys("你的帳號")
sleep(1)
driver.find_element_by_xpath("//input[@name='ctl00$ContentPlaceHolder1$AccountPassword1$txt_password']").click()
driver.find_element_by_xpath("//input[@name='ctl00$ContentPlaceHolder1$AccountPassword1$txt_password']").send_keys("你的密碼")
sleep(1)
driver.find_element_by_xpath("//input[@name='ctl00$ContentPlaceHolder1$AccountPassword1$btn_LoginHandler']").click()
sleep(2)
driver.get("https://elearn.hrd.gov.tw/mooc/user/mycourse.php")

基本上這些東西都跟上次寫的差不多~大家參考一下囉~挺好玩的~

實際結果 : 

擷取.PNG

 

 

arrow
arrow
    全站熱搜

    張郎屋 發表在 痞客邦 留言(0) 人氣()