英文:
Chrome driver issue in data bricks
问题
我在运行以下代码时遇到了Web驱动程序异常。
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.binary_location = "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/chromedriver_binary/chromedriver" # 用实际的Chrome二进制文件路径替换
driver = webdriver.Chrome(options=chrome_options)
print(driver.service.process.path)
错误信息如下:
WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/chromedriver_binary/chromedriver is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
以下是集群上安装的库:
我尝试了多种方法,手动下载了Chrome和驱动程序,但仍然没有成功。之后,我尝试了使用Firefox,但遇到了以下问题:
%sh
wget https://github.com/mozilla/geckodriver/releases/download/v0.24.0/geckodriver-v0.24.0-linux64.tar.gz -O /tmp/geckodriver.tar.gz
%sh
tar -xvzf /tmp/geckodriver.tar.gz -C /tmp
%sh
ls /tmp/gec*
%sh
/usr/bin/yes | sudo apt update --fix-missing > /dev/null 2>&1
%sh
sudo apt-get --yes --force-yes install firefox > /dev/null 2>&1
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options, executable_path='/tmp/geckodriver')
错误信息如下:
<command-1051731704975926>:6: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
driver = webdriver.Firefox(options=options, executable_path='/tmp/geckodriver')
WebDriverException: Message: Service /tmp/geckodriver unexpectedly exited. Status code was: 1
英文:
I am facing Web driver exception while running below code.
Code:
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
#driver = webdriver.Chrome()
#print(driver.service.executable_path)
chrome_options= Options()
chrome_options.add_argument("--headless")
chrome_options.binary_location = "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/chromedriver_binary/chromedriver" # Replace with the actual path to your Chrome binary
driver = webdriver.Chrome(options=chrome_options)
print(driver.service.process.path)
Error:
ebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/chromedriver_binary/chromedriver is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
below are the libraries installed on cluster:
have tried multiple things and tried to download manually chrome and driver but still no luck. After that have tried to do using firefox but for that getting below issue. Please suggest how to achieve this problem.
Firefox code:
%sh
wget https://github.com/mozilla/geckodriver/releases/download/v0.24.0/geckodriver-v0.24.0-linux64.tar.gz -O /tmp/geckodriver.tar.gz
%sh
tar -xvzf /tmp/geckodriver.tar.gz -C /tmp
%sh
ls /tmp/gec*
%sh
/usr/bin/yes | sudo apt update --fix-missing > /dev/null 2>&1
%sh
sudo apt-get --yes --force-yes install firefox > /dev/null 2>&1
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options =Options()
options.headless =True
driver=webdriver.Firefox(options=options, executable_path ='/tmp/geckodriver')
Error :
<command-1051731704975926>:6: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
driver=webdriver.Firefox(options=options, executable_path ='/tmp/geckodriver')
WebDriverException: Message: Service /tmp/geckodriver unexpectedly exited. Status code was: 1
答案1
得分: 0
你可以按照这个方法进行操作。
运行下面的代码来设置选项。
from selenium import webdriver
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument('--headless')
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--disable-gpu")
binary_path = "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/chromedriver_binary/chromedriver"
接下来,运行以下命令来安装稳定版本的 Chrome。
%sh
sudo curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add
sudo echo "deb https://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list
sudo apt-get -y update
sudo apt-get -y install google-chrome-stable
在这里,你可以看到 Chrome 的版本是 114.0.5735,与你在集群中安装的 Chrome 驱动程序相同。
然后,获取浏览器对象。
browser = webdriver.Chrome(service=Service(binary_path), options=options)
print(browser.service.process.args)
希望这些信息对你有帮助。
英文:
you can follow this approach.
Run below code for setting up options.
from selenium import webdriver
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument('--headless')
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--disable-gpu")
binary_path = "/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/chromedriver_binary/chromedriver"
Next, run below for installing stable chrome version.
%sh
sudo curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add
sudo echo "deb https://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list
sudo apt-get -y update
sudo apt-get -y install google-chrome-stable
Here, you can see the chrome version is 114.0.5735, it is same with the chromebinary you installed in cluster.
Then, get the browser object.
browser = webdriver.Chrome(service=Service(binary_path), options=options)
print(browser.service.process.args)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论