【问题标题】:NoneType object is not callable__ beautiful soupNoneType 对象不可调用__ 美丽的汤
【发布时间】:2013-06-13 07:11:09
【问题描述】:

这是我目前的代码

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

【问题讨论】:

    标签: python beautifulsoup


    【解决方案1】:

    看来你混淆了Beautiful Soup 3和4,你正在导入版本3,但是使用find_all,版本4的一个函数。这个函数是版本3中的findAll。所以如果你想继续使用第 3 版,您需要将其重写为:

    weather_res = weather.findAll('th')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-12
      • 1970-01-01
      • 2020-11-09
      • 2018-07-19
      • 1970-01-01
      • 1970-01-01
      • 2013-06-11
      相关资源
      最近更新 更多