1

私は Splinter を初めて使用しますが、Python を数回使用しました。だから私はスプリンターを使ってウェブサイトを自動化したいと思っていました。しかし、実行すると「ImportError: 名前のブラウザをインポートできません」というエラーが表示されます。

これが私のコードです。

from splinter import Browser

browser = Browser()
browser.visit('http://google.com')
browser.fill('q', 'splinter - python acceptance testing for web applications')
browser.find_by_name('btnG').click()

if browser.is_text_present('splinter.readthedocs.org'):
    print "Yes, the official website was found!"
else:
    print "No, it wasn't found... We need to improve our SEO techniques"

browser.quit()

ターミナルでは、これが得られます。

Traceback (most recent call last):
  File "splinter.py", line 3, in <module>
    from splinter import Browser
  File "/var/www/project/splinter.py", line 3, in <module>
    from splinter import Browser
ImportError: cannot import name Browser

エラーなしでこのプログラムを実行するにはどうすればよいですか? splinter.pyc の削除など、同様の問題の解決策を参照しましたが、役に立ちませんでした。

4

1 に答える 1

6

You have a local file named splinter.py , which is shadowing the library splinter as can be seen from the traceback -

Traceback (most recent call last):
File "splinter.py", line 3, in
from splinter import Browser

Rename that file , you should not name your python files or packages in a way that would shadow/mask the libraries.

于 2015-08-14T07:20:47.870 に答える