selenium - Gakgu/Gakgu.github.io GitHub Wiki

๊ฐœ์š”

์›น ํฌ๋กค๋ง์„ ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ. ์—ฌ๋Ÿฌ ์–ธ์–ด๋กœ ๋ฐ”์ธ๋”ฉ๋˜์—ˆ๋‹ค.

ํŒŒ์ด์ฌ

๋Œ€๋ถ€๋ถ„์˜ ์‚ฌ์šฉ๋ฒ•์€ Selenium with Python์— ์†Œ๊ฐœ๋˜์–ด ์žˆ๋‹ค.

๊ธฐ๋ณธ

chromedriver๋ฅผ ๋‹ค์šด๋ฐ›์€ ํ›„ ๊ธฐ๋ณธ path์— ์œ„์น˜์‹œํ‚ค๊ฑฐ๋‚˜ ์œ„์น˜๋ฅผ ์†Œ์Šค์—์„œ ๋ช…์‹œํ•œ๋‹ค.

from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://google.com")
driver.close()

ํฌ๋กฌ ์ˆจ๊ธฐ๊ธฐ

option = webdriver.ChromeOptions()
option.add_argument("headless")
driver = webdriver.Chrome(chrome_options=option)

์š”์†Œ ์ฐพ๊ธฐ

driver.find_element_by_id("id")
driver.find_elements_by_id("id")

driver.find_element_by_class_name("class name")
driver.find_elements_by_class_name("class name")

driver.find_element_by_xpath("//td[@class='title']")
driver.find_elements_by_xpath("//td[@class='title']")

๊ธ€์ž ์“ฐ๊ธฐ

input_id = driver.find_element_by_id("id")
input_id.clear()
input_id.send_keys("[email protected]")

์—”ํ„ฐ

from selenium.webdriver.common.keys import Keys
input_id.send_keys(Keys.ENTER)

ํด๋ฆญ

login_button= driver.find_element_by_class_name("login")
login_button.click()