我尝试使用 :
在 google colab 上初始化 seleniumfrom selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
print(chrome_options)
driver = webdriver.Chrome('chromedriver', options=chrome_options)
安装selenium后使用
%%shell
cat > /etc/apt/sources.list.d/debian.list <<'EOF'
deb [arch=amd64 signed-by=/usr/share/keyrings/debian-buster.gpg] http://deb.debian.org/debian buster main
deb [arch=amd64 signed-by=/usr/share/keyrings/debian-buster-updates.gpg] http://deb.debian.org/debian buster-updates main
deb [arch=amd64 signed-by=/usr/share/keyrings/debian-security-buster.gpg] http://deb.debian.org/debian-security buster/updates main
EOF
# Add keys
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys DCC9EFBF77E11517
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 648ACFD622F3D138
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 112695A0E562B32A
apt-key export 77E11517 | gpg --dearmour -o /usr/share/keyrings/debian-buster.gpg
apt-key export 22F3D138 | gpg --dearmour -o /usr/share/keyrings/debian-buster-updates.gpg
apt-key export E562B32A | gpg --dearmour -o /usr/share/keyrings/debian-security-buster.gpg
# Prefer debian repo for chromium* packages only
# Note the double-blank lines between entries
cat > /etc/apt/preferences.d/chromium.pref << 'EOF'
Package: *
Pin: release a=eoan
Pin-Priority: 500
Package: *
Pin: origin "deb.debian.org"
Pin-Priority: 300
Package: chromium*
Pin: origin "deb.debian.org"
Pin-Priority: 700
EOF
# Install chromium and chromium-driver
apt-get update
apt-get install chromium chromium-driver
# Install selenium
pip install selenium
这是来自帖子这里
我收到错误
<selenium.webdriver.chrome.options.Options object at 0x7aa3e3f26860>
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-46-123981fb5389> in <cell line: 99>()
97 print(chrome_options)
98
---> 99 driver = webdriver.Chrome('chromedriver', options=chrome_options)
100
101 def check_html_content(html_content, url):
TypeError: WebDriver.__init__() got multiple values for argument 'options'
如何在 google colab 上使用 selenium (python)?我对 selenium 选项等不太熟悉,所以我不确定如何使用它。如果有人能告诉我如何在 google colab 上使用 selenium python,我将非常感激。
Selenium
更改了新版本中的代码,看来您使用了非常旧的代码。
较新的版本需要:
Chrome(service=Service(executable_path="/path/to/chromedriver"), options=chrome_options)
但是最新版本可以自动下载驱动程序,所以你可以做
Chrome(options=chrome_options)