컴퓨터/Python_selenium

Python selenium 따라하기 kimfl

풍경소리^^ 2022. 8. 20. 18:24

https://www.youtube.com/watch?v=2EBrICPZVLY&t=704s 

kimfl01.py--------------------

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains

import time

driver = webdriver.Chrome()
url = 'https://www.daum.net/'
driver.get(url)
driver.maximize_window()
action = ActionChains(driver)

driver.find_element_by_css_selector(".link_login.link_kakaoid").click()
driver.find_element_by_css_selector("#id_email_2_label").click()
action.send_keys('miero@daum.net').perform()
action.reset_actions()
driver.find_element_by_css_selector("#id_password_3_label").click()
action.send_keys('비밀번호').send_keys(Keys.ENTER).perform()

while(True):
    	pass

https://kimflstudio.tistory.com/

 

김플 스튜디오

 

kimflstudio.tistory.com

selenium_option.py--------------------

# https://www.youtube.com/watch?v=3uWkbfT9PNc&list=PL5bK87xH5V1wKF4ErEB0X4Ltu6kAlBB7X&index=4

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
import os


options = Options()
# F12 - 네트워크 - F5 (새로고침) - 이름 첫번째 주소 선택 - 헤더 - 제일 밑에 user-agent
user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36"
options.add_argument(f"user-agent={user_agent}")

# user_data = os.path.join(os.getcwd(), "user_data")
user_data = "B:\\python\\vscode\\selenium" # user_data 폴더 만들어짐. 방문기록 # 주석처리하면 새 브라우저에서 접속하는게 된다
options.add_argument(f"user-data-dir={user_data}") # 주석처리하면 새 브라우저에서 접속하는게 된다

options.add_experimental_option("detach", True) # 화면이 꺼지지 않고 유지

options.add_argument("--start-maximized") # 최대 크기로 시작
# options.add_argument("--start-fullscreen") # 전체 화면(F11)으로 시작
# options.add_argument("window-size=500,500") # 화면 크기 지정

# options.add_argument("--headless") # 헤드리스 모드
# options.add_argument("--disable-gpu") # 헤드리스 잘 안될 때 같이 사용

# options.add_argument("--mute-audio") # 음소거
# options.add_argument("incognito") # 시크릿 모드

options.add_experimental_option("excludeSwitches", ["enable-logging"]) # 불필요한 메세지 제거
options.add_experimental_option("excludeSwitches", ["enable-automation"]) # 자동화 메세지 제거

service = Service(ChromeDriverManager().install())

driver = webdriver.Chrome(service=service, options=options)

driver.get("https://naver.com")

# print(driver.page_source[:1000])

# driver.quit()

https://www.youtube.com/watch?v=3uWkbfT9PNc&list=PL5bK87xH5V1wKF4ErEB0X4Ltu6kAlBB7X&index=4