【问题标题】:mechanize browser has no attributemechanize浏览器没有属性
【发布时间】:2016-01-11 15:48:45
【问题描述】:

我已经重写了两次,我看不到问题,我在 python 2 上安装了 mechanize,我没有同时使用制表符和空格,我只使用空格。

import urllib
from bs4 import BeautifulSoup
import re
import urlparse
import mechanize

url = "http://www.dailymail.co.uk/home/index.html"
br = mechanize.Browser()
br.open(url)

for link in br.links():
    print link

错误是

Traceback (most recent call last):
  File "mechanize.py", line 4, in <module>
    import mechanize
  File "/home/ro/Autoblog/mechanize/mechanize.py", line 8, in <module>
    br = mechanize.Browser()
AttributeError: 'module' object has no attribute 'Browser'

【问题讨论】:

  • /home/ro/Autoblog/mechanize/mechanize.py 是指向mechanize 的路径还是隐藏了真正的模块?
  • 是的,这就是问题所在,感谢您的帮助。

标签: python attributes mechanize


【解决方案1】:

您的 Python 文件的文件名为“mechanize.py”(/home/ro/Autoblog/mechanize/mechanize.py)。这掩盖了“机械化”模块的名称。由于这种命名空间冲突,您实际上是在导入自己的脚本:import mechanize

将“mechanize.py”脚本的名称更改为其他名称,您应该会很好。

【讨论】:

    【解决方案2】:

    基本上你有一个冲突文件,它来自你下载 mechanize 的 github,每个 mechanize 文件夹中有两个 _mechanize.py 所以,删除一个 mechanize 文件夹,它是 mechanize 文件夹内的第二个 mechanize 文件夹

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-24
      • 1970-01-01
      • 2014-12-14
      • 2014-01-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多