使用python mechanize“ImportError:无法导入名称浏览器”

时间:2016-10-07 11:55:13

标签: python html linux forms mechanize

我无法使用mechanize code)。导致错误的部分是

#!/usr/bin/python
import re
from mechanize import 
br = Browser()

我也试过

使用python3.5执行时,我发现以下错误:

# python mechanize.py
Traceback (most recent call last):
  File "mechanize.py", line 6, in <module>
    from mechanize import Browser
  File "/root/git/stakexchange-ask-question/mechanize.py", line 6, in <module>
    from mechanize import Browser
ImportError: cannot import name Browser

然而,这正是官方mechanize website

的建议

如果我将代码修改为

#!/usr/bin/python
import re
br = mechanize.Browser()

我也收到错误

   # python  mechanize.py
Traceback (most recent call last):
  File "mechanize.py", line 5, in <module>
    import mechanize
  File "/root/git/stakexchange-ask-question/mechanize.py", line 6, in <module>
    br =mechanize.Browser()
AttributeError: module 'mechanize' has no attribute 'Browser'

我已经使用

安装了mechanize
easy_install mechanize

2 个答案:

答案 0 :(得分:0)

您是否尝试过mechanize.Browser()?

答案 1 :(得分:0)

python版本必须至少3.0reference

使用

检查你的python版本
readlink -f $(which python) | xargs -I % sh -c 'echo -n "%: "; % -V'

但错误并非仅来自此。 mechanize未正确安装,我再次从source code安装。