관리 메뉴

JIHYUN JEONG

Mac(맥) / Selenium(셀레늄)네이버 로그인 캡챠(CAPTCHA)문제 해결 본문

Information Technology/Web

Mac(맥) / Selenium(셀레늄)네이버 로그인 캡챠(CAPTCHA)문제 해결

StopHyun 2019. 10. 25. 22:09

 

Selenium(셀레늄)으로 로그인 할 경우 캡챠(CAPTCHA)가 아래처럼 발생한다.

 

검색해본결과 Windows는 아래 두 곳을 참고하면 해결이 되는 듯 하다.

 

- https://hyrama.com/?p=693

 

Selenium chrome driver 네이버 캡차(Captcha) 무력화 - 히라마 블로그

네이버가 작년 9월(?)부터 사용자 입력을 제외한 소프트웨어적 입력을 통한 로그인을 막기 위해 Captcha 시스템을 도입했습니다. 이로 인해 Selenium을 이용하여 자동 로그인을 시도했던 사용자들이  Captcha에 탐지 당해 로그인을 하지 못하고 있습니다. Selenium Element send_keys Method Selenium을... Read More

hyrama.com

- https://neung0.tistory.com/34

 

selenium으로 네이버 자동 로그인하기

네이버는 셀레니움으로 로그인을 시도하면 캡챠 페이지가 뜬다. 아래는 시도한 코드와 로그인이 막힌 모습. from selenium import webdriver driver = webdriver.Chrome(r'C:\Users\smddu\Documents\chromedriver\..

neung0.tistory.com

하지만 우리 Mac(맥)유저는 복사 붙여 넣기 기능이 Ctrl + v 가 아니라

Command + v 이다.

 

위 두곳을 참조하여 열심히 핵심코드인 아래 부분을 열심히 했는데 안되다.

 

 

[참고소스]

ActionChains(self.driver).key_down(Keys.CONTROL).send_keys('v').key_up(Keys.CONTROL).perform()

 

 

[수정한 내소스]

ActionChains(self.driver).key_down(Keys.COMMAND).send_keys('v').key_up(Keys.COMMAND).perform()

 

열심히 공식 문서를 읽어봐도 위랑 똑같다.

 

https://seleniumhq.github.io/selenium/docs/api/py/webdriver/selenium.webdriver.common.action_chains.html?highlight=key_down

 

selenium.webdriver.common.action_chains — Selenium 3.14 documentation

selenium.webdriver.common.action_chains The ActionChains implementation, class selenium.webdriver.common.action_chains.ActionChains(driver)[source] ActionChains are a way to automate low level interactions such as mouse movements, mouse button actions, key

seleniumhq.github.io

 

 

운이 좋은 건지 모르겠는데 아래 문구를 찾았다. 자기는 Mac + Firefox를 사용해서 됫단다.

 

https://stackoverflow.com/questions/25215007/selenium-python-actionchains-doesnt-work

 

Selenium: Python ActionChains doesn't work

I am trying to do a simple Control + S in Chromedriver I tried webdriver.send_keys(Keys.CONTROL, "s") which didn't work I then tried ActionChains(driver).key_down(Keys.LEFT_CONTROL).key_down('s').

stackoverflow.com

 

크롬드라이버를 쓰고 있었는데 Firefox를 다운 받아서 시도해보기로 했다. 아래 경로에서 다운 받으면 된다.

 

https://github.com/mozilla/geckodriver/releases

 

mozilla/geckodriver

WebDriver for Firefox. Contribute to mozilla/geckodriver development by creating an account on GitHub.

github.com

 

주의 사항: 최신 v0.26.0은 카탈리나가 지원 되지 않으니 참고하기 바란다.

 

나는 0.26.0 밑에 있는 버전을 다운 받은 후 압축을 풀었다.

 

geckodriver를 /usr/local/bin에 넣어준다.(Shift + Command + G 를 눌러서 이동할 폴더 지정)

 

 

아래 두 모듈을 꼭 설치해 준다.

pip install pyperclip
pip install selenium

 

소스는 아래와 같다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import time
from selenium import webdriver
import pyperclip
 
driver = webdriver.Firefox(capabilities=None, executable_path='/usr/local/bin/geckodriver')
 
def copy_input(xpath, input):
    driver.find_element_by_xpath(xpath).click()
    time.sleep(2)
    ActionChains(driver).key_down(Keys.COMMAND).send_keys('v').key_up(Keys.COMMAND).perform()
 
 
user_id = 'user_id'
user_pw = 'user_password'
 
driver.implicitly_wait(3)
 
copy_input('//*[@id="id"]', user_id)
copy_input('//*[@id="pw"]', user_pw)
driver.find_element_by_xpath('//*[@id="frmNIDLogin"]/fieldset/input').click()
 

 

잘된다. 하하하하하 :) 맥(Mac) 쓰시는 분들 네이버 로그인 시 Chrome driver는 아무리 해도 안됩니다 ㅠㅠ 우리 필요하면 Firefox를 씁니다.

 

(혹시 그래도 안되시는 분은 Firefox를 다운로드 해보세요.https://www.mozilla.org/ko/firefox/new/)

 

이제까지 가장 빠른 Firefox 다운로드

더 빠른 페이지 로딩, 더 적은 메모리 사용량, 다양한 기능 탑재, 새로운 Firefox가 여기 있습니다.

www.mozilla.org

 

 

FIrefox는 잘되서 다행이네요.

 

 

도움이 되셨다면 커피한잔 어떤가요? 아니 광고라도 클릭 부탁드립니다 :) 도움이 됫길 바라며

 

Buy me a coffeeBuy me a coffee

Comments