Selenium ERROR在Linux中运行简单程序

问题描述 投票:1回答:1

我也是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
selenium selenium-webdriver python-3.7
1个回答
0
投票

你需要降级到python 3.6

或者,如果您没有gecko驱动程序,请执行以下步骤。

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
© www.soinside.com 2019 - 2024. All rights reserved.