搜索他們通過類過濾器下面是我code.`在找不到beautifulsoup標籤,當我通過字典
import urllib
from BeautifulSoup import *
html=urllib.urlopen('http://yellowpages.sulekha.com/coffee-shops-bars-restaurants_delhi')
soup=BeautifulSoup(html)
tags=soup.findAll("li",{ "class" : "list-item" })
print tags
我希望能夠找到其中有一個類所有的「禮」標籤「列表項」。當我執行上面的代碼,它返回一個空列表,但是當我鍵入它作爲
tags=soup.findall("li","list-item")
它返回與所有需要的「禮」的標籤正確的列表。任何人都可以告訴我爲什麼會發生這種情況?我使用python 2.7和beautifulsoup3。
無法評論python 2.7,但上面的代碼 - 你說的不工作,在python 3.5上工作得很好。我只是將'urllib.urlopen()'改爲'html = urllib.request.urlopen()'並修復了URL中的虛假空間。 –