Python에서 Selenium 사용하기 및 Error: “chromedriver” cannot be opened because the developer cannot be verified. Unable to launch the chrome browser 에러코드 해결

작성: 2021.03.18

수정: 2021.03.18

읽는시간: 00 분

Programming/Python

반응형

1. Python에서 Selenium  사용하기

Python에서 Selenium 을 이용하려면 chromedriver를 설치해야 합니다.

sites.google.com/a/chromium.org/chromedriver/downloads에서 본인의 버전에 맞는 드라이버를 선택해서 다운 받습니다.

 

Downloads - ChromeDriver - WebDriver for Chrome

WebDriver for Chrome

sites.google.com

 

제 mac에 설치된 chrome 버전을 확인하니 89 버전이라서 89 버전으로 들어가니 m1맥에 맞는 드라이버가 있어서 다운받았습니다.

conda에 selinium 도 설치했습니다.

conda install selenium

2.  에러코드 해결

Error: “chromedriver” cannot be opened because the developer cannot be verified. Unable to launch the chrome browser

chromedriver를 원하는 경로에 저장한 뒤에 아래 코드를 실행해보았습니다.

from bs4 import BeautifulSoup
import requests
from selenium import webdriver


URL = 'http://localhost:8080/MYSERVER/login'
driver = webdriver.Chrome(executable_path='/Users/shane/chromedriver')
driver.get(url=URL);

 

Error: “chromedriver” cannot be opened 
because the developer cannot be verified. 
Unable to launch the chrome browser

 

라는 에러가 뜨며 chromedriver를 실행하지 못합니다. Apple의 보안 정책 때문에 그렇습니다.

1. Terminal을 켭니다.

2. chromedriver 파일이 저장된 경로로 갑니다.

3. 아래의 명령어를 입력합니다.

xattr -d com.apple.quarantine chromedriver

 

그러면 chromedriver에 권한이 부여되며 잘 실행이 됩니다.

 

 

 

 

import time

from bs4 import BeautifulSoup
from selenium import webdriver


login = 'http://localhost:8080/MYSERVER/login.html'
secret = 'http://localhost:8080/MYSERVER/secret'
driver = webdriver.Chrome(executable_path='/Users/shane/chromedriver')

driver.get(login)
driver.find_element_by_name('id').send_keys('president')
driver.find_element_by_name('pw').send_keys('password')
time.sleep(1.5)

driver.find_element_by_id('mysubmit').click()
time.sleep(1)
driver.get(secret)

txt = driver.page_source
soup = BeautifulSoup(txt, 'html.parser')

for info in soup.select('td'):
    print(info.text)

이제 위 코드를 실행하면 스스로 로그인 해서 필요한 정보를 크롤링 해 오는 것을 확인 할 수 있습니다.

아래 사진을 클릭하면 실행 과정을 확인 할 수 있습니다.

 

 

반응형