2013-06-13 145 views
3

這是到目前爲止我的代碼NoneType對象不callable__美麗的湯

# -*- encoding: utf-8 -*- 

import urllib2 
from BeautifulSoup import BeautifulSoup as bs 
import json 


data = urllib2.urlopen('http://www.jma.go.jp/en/yoho/320.html') 

html_doc = data.read() 

soup = bs(html_doc) 

weather = soup.find('table',attrs={'class':'forecast'}) 
weather_res = weather.find_all('th') 

爲什麼我得到這個NoneType錯誤...

回答

4

看來你混淆美麗的湯3和4,你'導入版本3,但使用find_all,版本4的功能。此功能在版本3中爲findAll。因此,如果要繼續使用版本3,則需要將其重寫爲:

weather_res = weather.findAll('th')