首页 文章

NoneType对象不可调用_美丽的汤

提问于
浏览
3

到目前为止这是我的代码

# -*- 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 回答

  • 5

    看来你're confusing Beautiful Soup 3 and 4, you'正在重新导入版本3,但是使用 find_all ,版本4的函数 . 这个函数在版本3中是findAll . 所以如果你想继续使用版本3,你需要将其重写为:

    weather_res = weather.findAll('th')
    

相关问题