Python:Beautifulsoup列表为空

时间:2014-11-19 23:15:33

标签: python beautifulsoup

当我打印出g_data列表时,它是空的。里面应该有一些信息我做错了什么?

import requests
from bs4 import BeautifulSoup

url = 'http://www.yellowpages.com/search?search_terms=coffee&geo_location_terms=Los+Angeles%2C+CA'
r = requests.get(url)

soup = BeautifulSoup(r.content)

g_data = soup.find_all("div", {"class": "info"})

for item in g_data:
    print item.text

1 个答案:

答案 0 :(得分:0)

完全相同的代码适用于Ubuntu`14和Python2.7

您可以尝试将解析器更改为html5lib

pip install html5lib

然后,

soup = BeautifulSoup(r.content,'html5lib')