【发布时间】:2013-09-29 01:04:54
【问题描述】:
我正在尝试运行以下 python 脚本:
from selenium import webdriver
driver = webdriver.PhantomJS()
driver.get('https://www.everlane.com/collections/mens-luxury-tees/products/mens-v-antique')
driver.save_screenshot('screen.png') # save a screenshot to disk
print driver.current_url
images = driver.find_elements_by_tag_name('img')
for image in images:
print image.get_attribute('src')
但是,每次我尝试运行它时,我都会收到此错误:
FitValet-MacBook-Pro:desktop fitvalet$ python selenium.py
Traceback (most recent call last):
File "selenium.py", line 1, in <module>
from selenium import webdriver
File "/Users/fitvalet/Desktop/selenium.py", line 1, in <module>
from selenium import webdriver
ImportError: cannot import name webdriver
FitValet-MacBook-Pro:desktop fitvalet$
但是我已经使用pip install selenium 安装了模块并且安装良好。当我运行一个新的终端窗口时,输入python,然后输入from selenium import webdriver,它可以正常导入。如果我exit()python,然后重新输入再试一次,就会出现上面同样的错误,就是无法导入selenium。如果我重新打开终端,它会再次运行,但仅在终端 python 窗口中。我什至可以输入每一行代码,它可以在终端中很好地打印图像!
如果我只是尝试自己运行脚本,它永远不会起作用。关于为什么会这样的任何想法?谢谢!!!
【问题讨论】:
标签: python selenium python-module