NoneType对象不可调用beautifulsoup

时间:2013-06-13 07:11:10

标签: python beautifulsoup

这是我目前的代码

# -*- 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错误...

1 个答案:

答案 0 :(得分:5)

似乎你混淆了美丽的汤3和4,你正在导入版本3,但使用find_all,版本4的功能。这个功能是版本3中的findAll。所以如果你想继续使用版本3,您需要将其重写为:

weather_res = weather.findAll('th')