无法使Selenium WebDriver在Azure Databricks中工作 [英] cannot get selenium webdriver to work in azure databricks

查看:31
本文介绍了无法使Selenium WebDriver在Azure Databricks中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一些Python脚本可以抓取网站,并且运行良好。现在,我们希望在Azure Databricks中执行此操作。 我们以为在Databricks论坛上有以下帖子可以解决这个问题,但不幸的是,它不起作用。 (https://forums.databricks.com/questions/15480/how-to-add-webdriver-for-selenium-in-databricks.html?childToView=21347#answer-21347)

运行最后一段代码后得到的错误为: WebDriverException:消息:未知错误:找不到Chrome二进制文件(驱动程序信息:chromedriver=73.0.3683.68(47787ec04b6e38e22703e856e101e840b65afe72),Platform=linux 4.15.0-1050-azure x86_64)

最后一段代码如下所示:

    %py

    from selenium import webdriver

    chrome_options = webdriver.ChromeOptions()

    chrome_options.add_argument('--no-sandbox')

    chrome_options.add_argument('--headless')

    chrome_options.add_argument('--disable-dev-shm-usage')

    chrome_driver = "/tmp/chromedriver/chromedriver"

    driver = webdriver.Chrome(chrome_driver, 
    chrome_options=chrome_options)

    driver.get("https://www.google.com")

我发现了一个帖子,其中我必须给出二进制文件的位置: Selenium gives "selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary" on Mac

    options.binary_location = "/Applications/Google 
    Chrome.app/Contents/MacOS/Google Chrome"

但我不知道此二进制文件在Azure Databricks中的文件位置。

推荐答案

嗯,我对原来的Scipt做了一点小小的更改就可以工作了

    %sh /databricks/python3/bin/pip3 install selenium
    ==================
    %sh
    wget      
    https://chromedriver.storage.googleapis.com/73.0.3683.68/chromedriver_linux64.zip 
    -O /tmp/chromedriver_linux64.zip
    ==================
    %sh mkdir /tmp/chromedriver
    ================
    %sh
    unzip /tmp/chromedriver_linux64.zip -d /tmp/chromedriver/
    ==================
    %sh
    sudo add-apt-repository ppa:canonical-chromium-builds/stage
    ===================
    %sh
    /usr/bin/yes | sudo apt update
    ===================
    %sh
    /usr/bin/yes | sudo apt install chromium-browser
    ===================
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument('--no-sandbox')
    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--disable-dev-shm-usage')
    chrome_driver = "/tmp/chromedriver/chromedriver"
    driver = webdriver.Chrome(chrome_driver,chrome_options=chrome_options)
    driver.get("https://www.google.com")
此脚本下载并将Chrome更新到版本77。而赛车手已经73岁了。更改链接以下载chromedriver 77起到了作用。

    wget 
    https://chromedriver.storage.googleapis.com/77.0.3865.40/chromedriver_linux64.zip 

这篇关于无法使Selenium WebDriver在Azure Databricks中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆