標籤ID
driver.find_element(By.ID,"條件")
標籤屬性搜尋 CSS
driver.find_element(By.CSS_SELECTOR,"[屬性名稱=屬性的值]")
模擬user input
element=driver.find_elemnet(search欄位,"條件")
element.send_keys("input key)
模擬 user inpurt key
element.send_keys(Keys.ENTER)
=======================================
#https://www.youtube.com/watch?v=tR558fQAHz8
#爬 leetcode
#https://leetcode.com/accounts/login/
#pip install selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
import time #wating html loading
#chrom driver path https://chromedriver.chromium.org/downloads
options=Options()
options.chrome_executable_path="G:\我的雲端硬碟\PY\練習\chromdriver"
# Driver 物件
driver=webdriver.Chrome(options=options)
#連線到 LeetCode
driver.get("https://leetcode.com/accounts/login/")
#輸入帳號密碼, 按下 Enter
usernameInput=driver.find_element(By.ID, "id_login")
passwordInput=driver.find_element(By.ID, "id_password")
usernameInput.send_keys("myid")
passwordInput.send_keys("mypassword")
siginBtn=driver.find_element(By.ID, "signin_btn")
siginBtn.send_keys(Keys.ENTER)
#wait loading
time.sleep(5)
#連線到登入後才能取得Data
driver.get("https://leetcode.com/problemset/all/")
time.sleep(3)
statElement=driver.find_element(By.CSS_SELECTOR,"[data-difficulty=TOTAL]")
#print(statElement.text)
columns=statElement.text.split("\n") # List
print("已完成刷題數量: " + columns[1])
driver.close()