Giter Club home page Giter Club logo

google-colab-selenium's Introduction

The best way to use Selenium in Google Colab Notebooks!

  • Simple setup of Selenium and ChromeDriver.
  • Seamless integration with Google Colab.
  • Supports Undetected ChromeDriver for more advanced use cases.

Open In Colab

Installation

Basic usage:

%pip install google-colab-selenium

Use undetected-chromedriver version:

%pip install google-colab-selenium[undetected]

Basic Usage

import google_colab_selenium as gs

driver = gs.Chrome()
# Your code to interact with the driver here
# ...
driver.quit()

Undetected ChromeDriver

import google_colab_selenium as gs

driver = gs.UndetectedChrome()
# Your code to interact with the driver here
# ...
driver.quit()

Default Options

The google-colab-selenium package is preconfigured with a set of default options optimized for Google Colab environments. These defaults include:

  • --headless: Runs Chrome in headless mode (without a GUI).
  • --no-sandbox: Disables the Chrome sandboxing feature, necessary in the Colab environment.
  • --disable-dev-shm-usage: Prevents issues with limited shared memory in Docker containers.
  • --lang=en: Sets the language to English.

You are welcome to extend or override these options based on your needs:

from selenium.webdriver.chrome.options import Options
import google_colab_selenium as gs

custom_options = Options()
# Add your custom options here

driver = gs.Chrome(options=custom_options)

Contributing

Contributions are welcome! If you have a suggestion or an issue, please use the issue tracker to let me know.



Test it out for yourself!

Open In Colab

google-colab-selenium's People

Contributors

jpjacobpadilla avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

google-colab-selenium's Issues

unable to add_experimental_option

This is a fantastic package. I would like to disable automatic image downloads using add_experimental_option:

prefs = {
  "profile.managed_default_content_settings.images": 2,  
  "permissions.default.stylesheet": 2,  
}

options.add_experimental_option("prefs", prefs)

However, I get this error:

InvalidArgumentException: Message: invalid argument: cannot parse capability: goog:chromeOptions
from invalid argument: unrecognized chrome option: prefs

Is there some other way I should be doing this? Thanks!

An error will occur

!pip install google-colab-selenium
import google_colab_selenium as gs
driver = gs.Chrome() # <----Error

Google Search

Hey, how would we use the search bar in google here? Trying
search_box = driver.find_element_by_name("q")
but the find_element_by_name object doesn't seem to be here

Failed to start Chromedriver

Hey Jacob, I was trying to run the Undetected Chrome driver on your sample colab file. Seems like it's running into a problem.
I was hoping you could help fix the issue. Here's the error message I'm getting.

/usr/local/lib/python3.10/dist-packages/undetected_chromedriver/patcher.py in fetch_package(self)
286 logger.debug("downloading from %s" % download_url)
--> 287 return urlretrieve(download_url)[0]
288

/usr/lib/python3.10/urllib/request.py in urlretrieve(url, filename, reporthook, data)
240
--> 241 with contextlib.closing(urlopen(url, data)) as fp:
242 headers = fp.info()

/usr/lib/python3.10/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
215 opener = _opener
--> 216 return opener.open(url, data, timeout)
217

/usr/lib/python3.10/urllib/request.py in open(self, fullurl, data, timeout)
524 meth = getattr(processor, meth_name)
--> 525 response = meth(req, response)
526

/usr/lib/python3.10/urllib/request.py in http_response(self, request, response)
633 if not (200 <= code < 300):
--> 634 response = self.parent.error(
635 'http', request, response, code, msg, hdrs)

/usr/lib/python3.10/urllib/request.py in error(self, proto, *args)
562 args = (dict, 'default', 'http_error_default') + orig_args
--> 563 return self._call_chain(*args)
564

/usr/lib/python3.10/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
495 func = getattr(handler, meth_name)
--> 496 result = func(*args)
497 if result is not None:

/usr/lib/python3.10/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs)
642 def http_error_default(self, req, fp, code, msg, hdrs):
--> 643 raise HTTPError(req.full_url, code, msg, hdrs, fp)
644

HTTPError: HTTP Error 404: Not Found

The above exception was the direct cause of the following exception:

StartingChromeDriverError Traceback (most recent call last)
in <cell line: 1>()
----> 1 driver = gs.UndetectedChrome()
2 driver.get('https://www.google.com/')
3 print(driver.title)
4 driver.quit()

/usr/local/lib/python3.10/dist-packages/google_colab_selenium/undetected_chromedriver.py in init(self, options, keep_alive)
45
46 except Exception as e:
---> 47 raise StartingChromeDriverError("""
48 Failed to start ChromeDriver. This could be due to a number
49 of factors, such as missing dependencies or incorrect

StartingChromeDriverError:
Failed to start ChromeDriver. This could be due to a number
of factors, such as missing dependencies or incorrect
configuration settings.

issue regarding colab_selenium

CalledProcessError: Command '['sudo', 'apt', 'upgrade']' returned non-zero exit status 100.

The above exception was the direct cause of the following exception:

GoogleColabSeleniumError Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/google_colab_selenium/colab_selenium_manager.py in update_upgrade_apt(cls)
49
50 except Exception as e:
---> 51 raise GoogleColabSeleniumError('Failed to update and upgrade APT') from e
52
53 else:

GoogleColabSeleniumError: Failed to update and upgrade APT

    If you believe this isn't due to a configuration error on your end, please
    report the issue with any details you can provide about the steps leading
    up to this error.

Failed to find ChromeDriver

I believe this isn't due to a configuration error on my end, but it can't find ChromeDriver today (2024/4/25). Thank you for maintaining.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.