简体   繁体   English

机械化浏览器没有属性

[英]mechanize browser has no attribute

I've re written this twice, I can't see the problem,i've got mechanize installed on python 2 and I'm not doing both tabs and spaces, i'm only doing spaces.我已经写了两次,我看不出问题,我在 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

and the error is错误是

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'

The filename of your Python file is "mechanize.py" (/home/ro/Autoblog/mechanize/mechanize.py). 您的Python文件的文件名为“ mechanize.py”(/ home / ro / Autoblog / mechanize / mechanize.py)。 This shadows the name of the "mechanize" module. 这遮盖了“机械化”模块的名称。 Because of this namespace collision, you are actually importing your own script when you do: import mechanize . 由于名称空间冲突,您实际上在执行以下操作时会导入自己的脚本: import mechanize

Change the name of your "mechanize.py" script to something else and you should be good. 将您的“ mechanize.py”脚本的名称更改为其他名称,您应该会很好。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM