我们有一些 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 在 Mac 上给出“selenium.common.exceptions.WebDriverException:消息:未知错误:找不到 Chrome 二进制文件”
options.binary_location = "/Applications/Google
Chrome.app/Contents/MacOS/Google Chrome"
但我不知道此二进制文件在 Azure Databricks 中的文件位置。
好吧,在对原始脚本进行一些小改动后,我已经让它可以工作了
%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")
该脚本下载并更新了 chromium 至版本 77。而 chromedriver 为 73。更改链接以下载 chromedriver 77 就可以了。
wget
https://chromedriver.storage.googleapis.com/77.0.3865.40/chromedriver_linux64.zip
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)