Nach mehreren Versuchen mit Selenium-Einsatz auf Google-Colab habe ich versucht, testweise (!!) einen einfacheren Ansatz Weg zu finden, um Selenium auf Colab zu verwenden! Sehen
Die Kora-Bibliothek will ja im Grunde genommen eine bequeme Möglichkeit bieten, Selenium in Google Colab zu verwenden, ohne sich um die Verwaltung des ChromeDriver kümmern zu müssen. So jedenfalls hab ich das gedacht:
Hier ist ein Beispiel mit kora.selenium:
Code: Alles auswählen
!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()
Nun ja – die kora.selenium, der WebDriver (wd) wird soweit ich das verstanden habe, dann auch automatisch für Colab eingerichtet, und wir müssen uns keine Gedanken über den chrome_driver_path oder machen. Also, soweit ichs überblicke macht es die Kora-Bibliothek hier etwas einfacher mit der Konfiguration. Sie - so denke ich vereinfacht den Prozess der Verwendung von Selenium in einer Colab-Umgebung.
Aber wartet: sehr was ich zurückbekomme!?
Code: Alles auswählen
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'
hmm - was habe ich hier übersehen!?