Use selenium with chromedriver on Mac

后端 未结 4 1051
后悔当初
后悔当初 2021-01-31 06:30

I want to use selenium with chromedriver on Mac,but I have some troubles on it.

  1. I download the chromedriver from ChromeDriver - WebDriver for Chrome
  2. But I
4条回答
  •  野的像风
    2021-01-31 07:00

    selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH.

    To launch chrome browser using ChromeDriver you need to pass executable chromedriver location with executable itself into executable_path.

    You should try as below :-

    from selenium import webdriver
    
    PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
    DRIVER_BIN = os.path.join(PROJECT_ROOT, "bin/chromedriver_for_mac")
    
    browser = webdriver.Chrome(executable_path = DRIVER_BIN)
    browser.get('http://www.baidu.com/')
    

    Or set PATH variable using command with executable as :-

    export PATH=$PATH:/Users/wyx/project/python-scraping/se/bin/chromedriver_for_mac
    

    Then try to Initialize ChromeDriver as :-

    from selenium import webdriver
    
    browser = webdriver.Chrome()
    browser.get('http://www.baidu.com/')
    

提交回复
热议问题