Use selenium with chromedriver on Mac

后端 未结 4 1049
后悔当初
后悔当初 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 06:56

    For me worked like this without complicating things

    1. Download chromedriver from official link (notice version of Chrome browser)
    2. Unpack *.zip file and file chromedriver copy to location usr/local/bin/
    3. Remove any path you put in file and just go with driver = webdriver.Chrome()
    4. If probem still exist try to reopen PyCharm since sometimes need to be reopened in case to work
    0 讨论(0)
  • 2021-01-31 06:59

    For sake of simplicity:

    Download the chrome webdriver from this link. Copy the 'chromedriver' in the folder of python script.

    from selenium import webdriver
    import os
    
    url = 'http://www.webscrapingfordatascience.com/complexjavascript/'
    
    PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
    DRIVER_BIN = os.path.join(PROJECT_ROOT, "chromedriver")
    
    driver = webdriver.Chrome(executable_path = DRIVER_BIN)
    
    driver.get(url)
    
    input('Press ENTER to close the automated browser')
    
    driver.quit()
    
    0 讨论(0)
  • 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/')
    
    0 讨论(0)
  • 2021-01-31 07:12

    For me, installing chromedriver through homebrew worked like a charm on MacOS 11.

    brew install chromedriver && brew update 
    
    0 讨论(0)
提交回复
热议问题