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

2017. 8. 11. 01:37IT/Python

반응형
browser = webdriver.Chrome()
 

실행시, 다음과 같이 권한 오류가 발생하는 경우....

 

Traceback (most recent call last):

  File "/home/hodle/.local/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 74, in start

    stdout=self.log_file, stderr=self.log_file)

  File "/usr/lib/python3.5/subprocess.py", line 947, in __init__

    restore_signals, start_new_session)

  File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child

    raise child_exception_type(errno_num, err_msg)

PermissionError: [Errno 13] Permission denied

 

During handling of the above exception, another exception occurred:

 

Traceback (most recent call last):

  File "chromedriver_test.py", line 6, in <module>

    driver=webdriver.Chrome(chrome_path)

  File "/home/hodle/.local/lib/python3.5/site-packages/selenium/webdriver/chrome/webdriver.py", line 62, in __init__

    self.service.start()

  File "/home/hodle/.local/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 86, in start

    os.path.basename(self.path), self.start_error_message)

 

selenium.common.exceptions.WebDriverException: Message: 'python' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home 

 

 

아래를 참고하자.

 

For Linux 

1. Check you have installed latest version of chrome brwoser-> "chromium-browser -version" 
2. If not, install latest version of chrome "sudo apt-get install chromium-browser"
3. get appropriate version of chrome driver from http://chromedriver.storage.googleapis.com/index.html
4. Unzip the chromedriver.zip
5. Move the file to /usr/bin directory sudo mv chromedriver /usr/bin
6. Goto /usr/bin directory and you would need to run something like "chmod a+x chromedriver" to mark it executable. 
7. finally you can execute the code.

import os from selenium import webdriver from pyvirtualdisplay import Display display = Display(visible=0, size=(800, 600)) display.start() driver = webdriver.Chrome() driver.get("http://www.google.com") print driver.page_source.encode('utf-8') driver.quit() display.stop()

 

반응형