Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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'
like image 265
booberz Avatar asked Mar 14 '26 07:03

booberz


1 Answers

The filename of your Python file is "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.

Change the name of your "mechanize.py" script to something else and you should be good.

like image 114
Corey Goldberg Avatar answered Mar 16 '26 20:03

Corey Goldberg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!