我在直接从Google Colab使用Selenium时遇到困难。每当我在本地机器上运行下面的代码时,我都能成功,但是我想在Colab中测试同一个应用程序,但我测试的所有选项都不能成功。
import warnings
warnings.filterwarnings('ignore')
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.common.exceptions import InvalidSessionIdException
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from google.colab import drive
drive.mount('/content/gdrive', force_remount=True)
options = webdriver.ChromeOptions()
options.add_argument("--disable-blink-features=AutomationControlled")
options.add_argument('--ignore-certificate-errors-spki-list')
options.add_argument('--ignore-ssl-errors')
options.add_experimental_option('excludeSwitches', ['enable-logging'])
options.add_experimental_option("prefs", {"profile.managed_default_content_settings.images": 2})
options.add_argument("--no-sandbox")
options.add_argument("--disable-setuid-sandbox")
options.add_argument("--disable-dev-shm-using")
options.add_argument("--disable-extensions")
options.add_argument("--disable-gpu")
options.add_argument("start-maximized")
options.add_argument("disable-infobars")
options.add_argument(r"user-data-dir=.\cookies\\test")
options.binary_location = '/usr/bin/google-chrome'
driver = webdriver.Chrome(options=options, executable_path='/usr/bin/chromedriver') #Error occurs in this function
driver.implicitly_wait(5)
print("Current session is {}".format(driver.session_id))
我还运行了以下命令:
!apt-get update
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin
尝试运行上面的代码后,将出现以下消息:
**WebDriverException: Message: unknown error: no chrome binary at /usr/bin/google-chrome**
我做错什么了吗?
3条答案
按热度按时间0s7z1bwu1#
我创建了一个库来帮助简化。
oxalkeyp2#
尝试删除此行
并查看它是否与默认的二进制位置工作。不要忘记安装驱动程序
jhdbpxl93#