是否可以在google colab中以UC模式启动seleniumbase? 我使用此代码运行单元(之前没有使用该 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
<ipython-input-1-6d1d661a5df6> in <cell line: 10>()
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 <module>
244
245 try:
--> 246 import mouseinfo
247
248 def mouseInfo():
/usr/local/lib/python3.10/dist-packages/mouseinfo/__init__.py in <module>
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
你没有安装..
pip install pyautogui