pip install selenium
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
browser = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=chrome_options)
browser.get("https://www.naver.com")

★ 문제 및 해결
python라고 입력하고 인터프리터로 실행하면 편하게 실습할 수 있음from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
browser = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=chrome_options)
browser.get("https://www.naver.com")
browser.back()
browser.forward()
browser.refresh()
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
browser = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=chrome_options)
browser.get("https://www.naver.com")
search_bar = browser.find_element(By.ID, "query")
search_bar.send_keys("별 헤는 밤")
search_bar.send_keys(Keys.ENTER)

from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
browser = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=chrome_options)
browser.get("https://www.naver.com")
search_bar = browser.find_element(By.ID, "query")
search_bar.send_keys("별 헤는 밤")
search_bar.send_keys(Keys.RETURN)
link = browser.find_elements(By.TAG_NAME, "a")
for l in link:
l.get_attribute("href")

from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
browser = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=chrome_options)
browser.get("https://www.naver.com")
browser.get("https://www.daum.net")
daum_search_bar = browser.find_element(By.NAME, "q")
daum_search_bar.send_keys("참회록")
daum_search_button = browser.find_element(By.XPATH, "//*[@id='daumSearch']/fieldset/div/div/button[3]") # " -> '로 수정
daum_search_button.click()

from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
browser = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=chrome_options)
browser.get("https://www.naver.com")
browser.quit()
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
browser = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=chrome_options)
browser.get("https://www.naver.com")
login_button = browser.find_element(By.CSS_SELECTOR, ".MyView-module__link_login___HpHMW")
login_button.click()
browser.find_element(By.ID, "id").send_keys("wrong_id")
browser.find_element(By.ID, "pw").send_keys("wrong_passwd")
browser.find_element(By.ID, "log.login").click()
time.sleep(3)
browser.find_element(By.ID, "id").clear()
browser.find_element(By.ID, "id").send_keys("correct_id")
browser.find_element(By.ID, "pw").send_keys("correct_passwd")
browser.find_element(By.ID, "log.login").click()
print(browser.page_source) # 현재 페이지에 있는 모든 html 파일을 출력함
#browser.quit()

※ 네이버 자동 인증 방지 기능으로 인해 로그인이 되지 않음

from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
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
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
browser = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=chrome_options)
browser.maximize_window() # 창 최대화
browser.get("https://flight.naver.com")
depart_date = browser.find_element(By.XPATH, '//button[text() = "가는 날"]')
depart_date.click()
time.sleep(1)
start_day = browser.find_elements(By.XPATH, '//b[text() = "27"]')
start_day[8].click() # 글을 작성할 때는 2월이므로 2월이 [0]에 해당 됨
end_day = browser.find_elements(By.XPATH, '//b[text() = "28"]')
end_day[9].click()
arrival = browser.find_element(By.XPATH, '//b[text() = "도착"]')
arrival.click()
time.sleep(1)
barcelona = browser.find_element(By.XPATH, '//button[contains(text(), "바르셀로나")]')
barcelona.click()
search = browser.find_element(By.XPATH, '//span[contains(text(), "항공권 검색")]')
search.click()
