我也是python和Linux的新手。我尝试在python 3.7中安装Selenium 但我得到了错误:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://www.ubuntu.com/')
输出
Traceback (most recent call last):
File "test.py", line 1, in <module>
from selenium import webdriver
File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/__init__.py", line 18, in <module>
from .firefox.webdriver import WebDriver as Firefox # noqa
File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 29, in <module>
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 26, in <module>
from .webelement import WebElement
File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/remote/webelement.py", line 37, in <module>
from StringIO import StringIO as IOStream File
"/usr/lib/python3.7/StringIO.py", line 40
raise ValueError, "I/O operation on closed file"
^ SyntaxError: invalid syntax
答案 0 :(得分:0)
您需要降级到python 3.6
或者,如果您没有壁虎驱动程序,请执行以下步骤。
wget https://github.com/mozilla/geckodriver/releases/download/v0.23.0/geckodriver-v0.23.0-linux64.tar.gz
sudo sh -c 'tar -x geckodriver -zf geckodriver-v0.23.0-linux64.tar.gz -O > /usr/bin/geckodriver'
sudo chmod +x /usr/bin/geckodriver
rm geckodriver-v0.23.0-linux64.tar.gz