How can we use Selenium Webdriver in colab.research.google.com?

后端 未结 4 598
野趣味
野趣味 2020-12-02 18:59

I want to use Selenium Webdriver of Chrome in colab.research.google.com for fast processing. I was able to install Selenium using !pip install selenium but the

相关标签:
4条回答
  • 2020-12-02 19:39

    I made my own library to make it easy.

    !pip install kora -q
    from kora.selenium import wd
    wd.get("https://www.website.com")
    
    0 讨论(0)
  • 2020-12-02 19:49

    You can can rid of using .exe file by using WebDriverManager so instead of this

    System.setProperty("webdriver.gecko.driver", "driverpath/.exe");
    WebDriver driver = new FirefoxDriver();
    

    you will be writing this

    WebDriverManager.firefoxdriver().setup();
    WebDriver driver = new FirefoxDriver();
    

    All you need is add the dependecy to the POM file(Im assuming you using maven or some build tool) Please see my full answer about how to use this in this link Using WebdriverManager

    0 讨论(0)
  • 2020-12-02 20:02

    You can do it by installing the chromium webdriver and adjusting some options such that it does not crash in 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',chrome_options=chrome_options)
    wd.get("https://www.webite-url.com")
    
    0 讨论(0)
  • 2020-12-02 20:02

    this one worked in colab

    !pip install selenium
    !apt-get update 
    !apt install chromium-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',chrome_options=chrome_options)
    driver =webdriver.Chrome('chromedriver',chrome_options=chrome_options)
    
    0 讨论(0)
提交回复
热议问题