Используйте seleniumbase в Google ColabPython

Программы на Python
Ответить
Anonymous
 Используйте seleniumbase в Google Colab

Сообщение Anonymous »

Можно ли запустить seleniumbase в режиме UC в Google Colab?
Я запустил ячейку с помощью этого кода (раньше никакие другие ячейки не запускались с этой средой выполнения Colab):

Код: Выделить всё

!sudo apt update && sudo apt upgrade
!curl -o google-chrome-stable_current_amd64.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
!sudo apt install ./google-chrome-stable_current_amd64.deb -y
!rm google-chrome-stable_current_amd64.deb
!apt-get install -y xvfb && apt-get install x11-utils
!pip install seleniumbase

from seleniumbase import SB

with SB(uc=True, headless=False, xvfb=True) as sb:
print(f'{sb = }')
Ошибка произошла на строке with SB:

Код: Выделить всё

PyAutoGUI is required for UC Mode on Linux! Installing now...

---------------------------------------------------------------------------

ModuleNotFoundError                       Traceback (most recent call last)

/usr/local/lib/python3.10/dist-packages/seleniumbase/fixtures/base_case.py in __activate_virtual_display_as_needed(self)
13864                     try:
> 13865                         import pyautogui
13866                         with suppress(Exception):

ModuleNotFoundError: No module named 'pyautogui'

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)

9 frames

 in ()
8 from seleniumbase import SB
9
---> 10 with SB(uc=True, headless=False, xvfb=True) as sb:
11   print(f'{sb = }')

/usr/lib/python3.10/contextlib.py in __enter__(self)
133         del self.args, self.kwds, self.func
134         try:
--> 135             return next(self.gen)
136         except StopIteration:
137             raise RuntimeError("generator didn't yield") from None

/usr/local/lib/python3.10/dist-packages/seleniumbase/plugins/sb_manager.py in SB(test, rtf, raise_test_failure, browser, headless, headless1, headless2, locale_code, protocol, servername, port, proxy, proxy_bypass_list, proxy_pac_url, multi_proxy, agent, cap_file, cap_string, recorder_ext, disable_cookies, disable_js, disable_csp, enable_ws, enable_sync, use_auto_ext, undetectable, uc_cdp_events, uc_subprocess, log_cdp_events, incognito, guest_mode, dark_mode, devtools, remote_debug, enable_3d_apis, swiftshader, ad_block_on, host_resolver_rules, block_images, do_not_track, chromium_arg, firefox_arg, firefox_pref, user_data_dir, extension_zip, extension_dir, disable_features, binary_location, driver_version, skip_js_waits, wait_for_angularjs, use_wire, external_pdf, window_position, window_size, is_mobile, mobile, device_metrics, xvfb, xvfb_metrics, start_page, rec_print, rec_behave, record_sleep, data, var1, var2, var3, variables, account, environment, headed, maximize, disable_ws, disable_beforeunload, settings_file, position, size, uc, undetected, uc_cdp, uc_sub, locale, log_cdp, ad_block, server, guest, wire, pls, sjw, wfa, save_screenshot, no_screenshot, page_load_strategy, timeout_multiplier, js_checking_on, slow, demo, demo_sleep, message_duration, highlights, interval, time_limit)
1209             proxy_helper.remove_proxy_zip_if_present()
1210     start_time = time.time()
-> 1211     sb.setUp()
1212     test_passed = True  # This can change later
1213     teardown_exception = None

/usr/local/lib/python3.10/dist-packages/seleniumbase/fixtures/base_case.py in setUp(self, masterqa_mode)
14916         if not hasattr(self, "is_nosetest") or not self.is_nosetest:
14917             # Xvfb Virtual Display activation for Linux
> 14918             self.__activate_virtual_display_as_needed()
14919
14920         # Dashboard pre-processing:

/usr/local/lib/python3.10/dist-packages/seleniumbase/fixtures/base_case.py in __activate_virtual_display_as_needed(self)
13882                             "pyautogui", version=constants.PyAutoGUI.VER
13883                         )
> 13884                         import pyautogui
13885                         pyautogui_is_installed = True
13886                     if (

/usr/local/lib/python3.10/dist-packages/pyautogui/__init__.py in 
244
245 try:
--> 246     import mouseinfo
247
248     def mouseInfo():

/usr/local/lib/python3.10/dist-packages/mouseinfo/__init__.py in 
221             raise
222
-->  223     _display = Display(os.environ['DISPLAY'])
224
225     def _linuxPosition():

/usr/local/lib/python3.10/dist-packages/Xlib/display.py in __init__(self, display)
87                              - self.display.info.min_keycode + 1))
88
---> 89         # Translations for keysyms to strings.
90         self.keysym_translations = {}
91

/usr/local/lib/python3.10/dist-packages/Xlib/display.py in __init__(self, *args, **keys)
69         r = request.InternAtom(display = self, name = atomname, only_if_exists = only_if_exists)
70
---> 71          # don't cache NONE responses in case someone creates this later
72         if r.atom != X.NONE:
73             self._atom_cache[atomname] = r.atom

/usr/local/lib/python3.10/dist-packages/Xlib/protocol/display.py in __init__(self, display)
82         # for a detailed explanation
83         self.send_recv_lock = lock.allocate_lock()
---> 84         self.send_active = 0
85         self.recv_active = 0
86

ValueError: not enough values to unpack (expected 5, got 4)
Вы можете прочитать весь вывод здесь: https://pastebin.com/LeBpz231

Подробнее здесь: https://stackoverflow.com/questions/791 ... ogle-colab
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»