본문 바로가기
공부/오류

selenium 에서 firefox 사용 및 내가 겪은 오류(cent os)

by 촌쥐 2021. 1. 20.

인터넷에 찾아보면 파이어폭스는 자체 내장 웹드라이버로 없어도 된다고 하는 말들이 있지만 

나 같은 경우 드라이버가 없으면 되지 않았다. 

 

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

 

Releases · mozilla/geckodriver

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

github.com

여기서 웹드라이버(geckodriver)를 받아준다. 파이어폭스를 최신으로 업데이트 중이라면 가장 최신 버전을 받아주면 된다. 

 

나 같은 경우 21.01.20기준 78버전 파이어폭스를 사용중 0.29.0 버전을 사용해도 큰 문제없었다. 

 

그 후 크롬 사용할때와 동일하게 사용하면 된다.

from selenium import webdriver

driver = webdriver.Firefox(executable_path="geckdriver 경로")

 

이후 겪은 오류

 

executable may have wrong permissions. 

 

이 오류는 크롬 드라이버나 파이어폭스 드라이버나 상관없이 떴다고한다. 

 

해결책 1 

 

경로를 제대로 작성한다. 상대경로로 되어있다면 절대경로로 바꿔주자.

물론 난 이걸로 해결되지 않았다.

 

해결책 2

 

드라이버의 권한을 설정 

https://baldeagle.tistory.com/40

 

Python 웹 크롤러 ChromeDriver 예외 처리(권한)

browser = webdriver.Chrome() 실행시, 다음과 같이 권한 오류가 발생하는 경우.... Traceback (most recent call last): File "/home/hodle/.local/lib/python3.5/site-packages/selenium/webdriver/common/servi..

baldeagle.tistory.com

드라이버가 있는 폴더로 가서 chmod +x (파폭 or 크롬 드라이버) 해주면 잘 작동 된다. 

 

실행권한을 준다는 뜻으로 알고 있다.

 

 

이후 만약 ssh 등으로 원격 사용중이라면 

 

https://stackoverflow.com/questions/46809135/webdriver-exceptionprocess-unexpectedly-closed-with-status-1/47642457

 

Webdriver Exception:Process unexpectedly closed with status: 1

I try to run a selenium program on a Linux machine.But I got the exceptions: Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/site-

stackoverflow.com

from selenium import webdriver
from selenium.webdriver import FirefoxOptions

opts = FirefoxOptions()
opts.add_argument("--headless")
driver = webdriver.Firefox(firefox_options=opts,executable_path="geckdriver 경로")

이런식으로 작성해주면 웹브라우저가 뜨지않고 실행된다

댓글