2015-10-13 70 views
2

我已經寫了兩次,我看不到問題,我已經機械化安裝在python 2上,我沒有做標籤和空格,我只做空間。機械化瀏覽器沒有任何屬性

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' 
+1

'/ home/ro/Autoblog/mechanize/mechanize.py'是'mechanize'的路徑,還是它映射到真實模塊? –

+0

是的,這是問題,感謝您的幫助。 – booberz

回答

3

你的Python文件的文件名是 「mechanize.py」(/home/ro/Autoblog/mechanize/mechanize.py)。這會影響「機械化」模塊的名稱。由於這種命名空間衝突,您實際上在導入自己的腳本時:import mechanize

將您的「mechanize.py」腳本的名稱更改爲其他名稱,您應該很好。