본문 바로가기
SW programming/Python

[Python Anywhere] Selenium 모듈 적용하는 법

by 고뭉나무 2021. 5. 27.

 

Error message

만약 Python anywhere에서 selenium 패키지(모듈)을 사용했는데 아래와 같은 error message가 출력된다면, 아래 가이드를 따라하면 된다.

 

"Permission denied"

OSError: [Errno 13] Permission denied

 

Selenium 패키지가 제대로 설치하기

'pip3 install selenium'을 하는 것이 일반적이나 --user 명령어까지 사용해야 된다.

그리고 혹여나 과거 버전으로 설치되어 있을 수 있으니 --upgrade 명령어까지 추가해서 실행하는 것이 좋다.

pip3 install --user --upgrade selenium

 

 

소스코드 안에서 Selenium 함수 활용하기

이제 설치는 완료되었고 내가 실행하고자 하는 소스코드에서 아래 코드를 추가해주면 된다.


보통의 IDE에서는 아래 코드로 실행하면 되지만, Python anywhere는 조금 다르게 짜줘야 한다.

 

먼저 보통의 IDE 툴에서 selenium 실행할 때,

from selenium import webdriver

#다운로드한 chromedriver가 있는 위치를 가리킴
driver = webdriver.Chrome('/home/--/chromedriver')
url = "https://www.google.com"
driver.get(url)

 

그러나 Python anywhere에서는 다음과 같이 사용하자

from selenium import webdriver

#Python anywhere에서 사용할 때
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")

driver = webdriver.Chrome(options=chrome_options)
url = "https://www.google.com"
driver.get(url)

 

참조: https://help.pythonanywhere.com/pages/selenium/

 

-끄읏 :)

반응형

댓글