'NoneType'对象不是可调用beautifulsoup错误,而使用get_text [英] 'NoneType' object is not callable beautifulsoup error while using get_text

查看:236
本文介绍了'NoneType'对象不是可调用beautifulsoup错误,而使用get_text的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写这篇code从网页中提取所有文本:

I wrote this code for extracting all text from a web page:

from BeautifulSoup import BeautifulSoup
import urllib2

soup = BeautifulSoup(urllib2.urlopen('http://www.pythonforbeginners.com').read())
print(soup.get_text())

问题是我得到这个错误:

The problem is I get this error:

print(soup.get_text())
TypeError: 'NoneType' object is not callable

如何解决这个任何想法?

Any idea about how to solve this?

推荐答案

该方法被称为 soup.getText(),即驼峰格式。

The method is called soup.getText(), i.e. camelCased.

为什么你会得到类型错误而不是 AttributeError的这里是一个谜给我!

Why you get TypeError instead of AttributeError here is a mystery to me!

这篇关于'NoneType'对象不是可调用beautifulsoup错误,而使用get_text的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆