我们如何在 colab.research.google.com 中使用 Selenium Webdriver?
·
问题:我们如何在 colab.research.google.com 中使用 Selenium Webdriver?
我想在 colab.research.google.com 中使用 Chrome 的 Selenium Webdriver 进行快速处理。我能够使用!pip install selenium安装 Selenium,但 chrome 的 webdriver 需要 webdriverChrome.exe 的路径。我应该如何使用它?
P.S.-colab.research.google.com 是一个在线平台,为与深度学习相关的快速计算问题提供 GPU。请避免使用 webdriver.Chrome(path) 等解决方案。
解答
您可以通过安装 chromium webdriver 并调整一些选项来做到这一点,使其不会在 google colab 中崩溃:
!pip install selenium
!apt-get update # to update ubuntu to correctly run apt install
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin
import sys
sys.path.insert(0,'/usr/lib/chromium-browser/chromedriver')
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
wd = webdriver.Chrome('chromedriver',options=chrome_options)
wd.get("https://www.webite-url.com")
更多推荐

所有评论(0)