Selenium auf Google-Colab: ein Test mit der Kora-Bibliothek - um die Verwaltung des ChromeDriver zu vereinfachen

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
Benutzeravatar
say_hello
User
Beiträge: 51
Registriert: Sonntag 14. Oktober 2012, 12:33

hallo und guten Abend, :)

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: :geek:


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'


hier die colab-Umgebung: https://colab.research.google.com/drive ... sp=sharing


hmm - was habe ich hier übersehen!?
:geek: :roll:
Benutzeravatar
__blackjack__
User
Beiträge: 13185
Registriert: Samstag 2. Juni 2018, 10:21
Wohnort: 127.0.0.1
Kontaktdaten:

`kora` und `selenium` passen nicht zusammen. In `selenium` hat sich die Signatur von `Webdriver.__init__()` geändert, so das `options` das erste Positionsargument ist. Also wird bei ``Chrome('chromedriver',options=options)`` zweimal `options` übergeben — einmal als Positionsargument und einmal als Schlüsselwortargument.
“There will always be things we wish to say in our programs that in all known languages can only be said poorly.” — Alan J. Perlis
Antworten