Issue
Selenium in Google Colab without having to worry about managing the ChromeDriver executable - i tried an example using kora.selenium
after serveral hard times with selenium and google-colab i tried to get a easier way to user selenium no cloab! See
The kora library provides a convenient way to use Selenium in Google Colab without having to worry about managing the ChromeDriver executable. today i tried out the an example using kora.selenium:
see my approach:
from kora.selenium import wd # web driver
print(wd.session_id) # 8be87366df11b09b552fb4ad7efbd696
https://stackoverflow.com/questions/69144967/is-running-selenium-on-google-colab-possible
!pip install kora
from kora.selenium import wd
# Example: Open Google and search for a term
search_term = "Hello, Google Colab!"
wd.get("https://www.google.com/")
search_box = wd.find_element("name", "q")
search_box.send_keys(search_term)
search_box.submit()
# Wait for a few seconds to let the results load
wd.implicitly_wait(5)
# Print the title of the page
print("Page title:", wd.title)
# Close the browser window
wd.quit()
well - the kora.selenium, the WebDriver (wd) is automatically set up for colab, and we don't need to worry about the chrome_driver_path or any other configuration. This simplifies the process of using Selenium in a Colab environment.
but wait: see what i i get back!?
this is annoying:
Collecting kora
Downloading kora-0.9.20-py3-none-any.whl (57 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 57.7/57.7 kB 1.8 MB/s eta 0:00:00
Requirement already satisfied: ipython in /usr/local/lib/python3.10/dist-packages (from kora) (7.34.0)
Requirement already satisfied: fastcore in /usr/local/lib/python3.10/dist-packages (from kora) (1.5.29)
Requirement already satisfied: pip in /usr/local/lib/python3.10/dist-packages (from fastcore->kora) (23.1.2)
Requirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from fastcore->kora) (23.2)
Requirement already satisfied: setuptools>=18.5 in /usr/local/lib/python3.10/dist-packages (from ipython->kora) (67.7.2)
Collecting jedi>=0.16 (from ipython->kora)
Downloading jedi-0.19.1-py2.py3-none-any.whl (1.6 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.6/1.6 MB 9.4 MB/s eta 0:00:00
Requirement already satisfied: decorator in /usr/local/lib/python3.10/dist-packages (from ipython->kora) (4.4.2)
Requirement already satisfied: pickleshare in /usr/local/lib/python3.10/dist-packages (from ipython->kora) (0.7.5)
Requirement already satisfied: traitlets>=4.2 in /usr/local/lib/python3.10/dist-packages (from ipython->kora) (5.7.1)
Requirement already satisfied: prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from ipython->kora) (3.0.43)
Requirement already satisfied: pygments in /usr/local/lib/python3.10/dist-packages (from ipython->kora) (2.16.1)
Requirement already satisfied: backcall in /usr/local/lib/python3.10/dist-packages (from ipython->kora) (0.2.0)
Requirement already satisfied: matplotlib-inline in /usr/local/lib/python3.10/dist-packages (from ipython->kora) (0.1.6)
Requirement already satisfied: pexpect>4.3 in /usr/local/lib/python3.10/dist-packages (from ipython->kora) (4.9.0)
Requirement already satisfied: parso<0.9.0,>=0.8.3 in /usr/local/lib/python3.10/dist-packages (from jedi>=0.16->ipython->kora) (0.8.3)
Requirement already satisfied: ptyprocess>=0.5 in /usr/local/lib/python3.10/dist-packages (from pexpect>4.3->ipython->kora) (0.7.0)
Requirement already satisfied: wcwidth in /usr/local/lib/python3.10/dist-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->ipython->kora) (0.2.13)
Installing collected packages: jedi, kora
Successfully installed jedi-0.19.1 kora-0.9.20
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-3-495f2524b7a6> in <cell line: 3>()
1 get_ipython().system('pip install kora')
2
----> 3 from kora.selenium import wd
4
5 # Example: Open Google and search for a term
/usr/local/lib/python3.10/dist-packages/kora/selenium.py in <module>
11 options.add_argument('--disable-dev-shm-usage')
12 # create a webdriver instance, ready to use
---> 13 wd = Chrome('chromedriver',options=options)
14
15 # make it easier to query and explore elements
TypeError: WebDriver.__init__() got multiple values for argument 'options'
see the colab: https://colab.research.google.com/drive/15BgMqgfkzo4a3ocX3ORpjGXUoVVxN56o?usp=sharing
any ideas here - how to get the tiny example up and runing!?
Solution
I made Google-Colab-Selenium to solve this problem. It manages the executable and the required Selenium Options for you.
Answered By - Jacob
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.