2017-03-17 47 views
0

我已經下載了Beautifulsoup並希望在我的python程序中導入它。我輸入了我的python程序如下:有人可以幫我使用Beautifulsoup去掉html嗎?

import urllib 
from BeautifulSoup import * 
url = raw_input('Enter - ') 
html = urllib.urlopen(url).read() 
soup = BeautifulSoup(html) 
tags = soup('a') 
for tag in tags: 
    print 'TAG:',tag 
    print 'URL:',tag.get('href', None) 
    print 'Contents:',tag.contents[0] 
    print 'Attrs:',tag.attrs 

現在我已將它保存在不同的文件夾中。 當我嘗試運行該程序時,出現以下錯誤。

error message

那麼,什麼可能是這個原因,我怎樣才能使它發揮作用? 在此先感謝! 我使用Python 2.7.13並將導入在裏面工作嗎? 我試圖導入BS4,它給了進口不被識別爲一個內部或外部命令

+0

Python路徑是否正確保存? –

+2

試試這個:'從BS4進口BeautifulSoup'的[使用Python處理BeautifulSoup圖書館] –

+1

可能的複製(http://stackoverflow.com/questions/13000180/using-beautifulsoup-library-with-python) –

回答

1
from bs4 import BeautifulSoup 

bs4是一個庫,你應該將其導入。

文獻:Quick Start

+0

我使用Python 2.7.13並且會_import_在裏面工作嗎?我試過導入** bs4 **,它給**導入不被識別爲內部或外部命令** – CandyManas