네이버 자동 로그인

배코딩·2022년 11월 28일
0

프로젝트

목록 보기
2/3

Selenium, pyperclip 라이브러리 설치를 먼저 하자.

cmd 또는 anaconda prompt를 관리자 권한으로 실행 후

pip install selenium==4.1.0
pip install webdriver-manager==3.5.2
pip install pyperclip




python 코드 (캡차 우회를 위해 pyperclip을 사용했으나 추후 막힐 수도 있음)

# 셀레니움 라이브러리
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
from selenium import webdriver

import time # 과도한 트래픽으로 인한 IP 차단 방지를 위해 지연 시간 두기

import warnings
warnings.filterwarnings("ignore") # 불필요한 warning 메시지 끄기

import pyperclip # 클립보드에 값을 저장할 수 있게 해주는 라이브러리




# 크롬드라이버(가상브라우저) 다운 및 세팅
service = Service(executable_path=ChromeDriverManager().install())  

# 가상브라우저 실행 및 객체 저장
driver = webdriver.Chrome(service=service)




# 웹 페이지 연결 (로딩을 위해 3초 지연)
driver.get('https://www.naver.com/')
time.sleep(3)

# 로그인 버튼을 클래스 명으로 찾아 클릭
driver.find_element_by_class_name('link_login').click()
time.sleep(3)

# 아이디를 클립보드에 저장 후 아이디 입력하는 input란에 넣기 (ctrl+v를 Key로 보냄)
pyperclip.copy('아이디')
driver.find_element_by_id('id_line').find_element_by_class_name('input_text').send_keys(Keys.CONTROL, 'v')
time.sleep(1)

# 비밀번호도 아이디랑 똑같이
pyperclip.copy('비밀번호')
driver.find_element_by_id('pw_line').find_element_by_class_name('input_text').send_keys(Keys.CONTROL, 'v')
time.sleep(1)

# 로그인 버튼 클릭 (id로 찾든 xpath로 찾든 css selector로 찾든 상관없음)
driver.find_element_by_id('log.login').click()
time.sleep(3)

# 가상 브라우저 닫을 때 코드
# driver.close()
# driver.quit()
profile
PS, 풀스택, 앱 개발, 각종 프로젝트 내용 정리 (https://github.com/minsu-cnu)

0개의 댓글