[英]NoneType Error when using Beautiful Soup object inside function
为什么该代码段的倒数第二行成功完成,但是最后一个给出错误: TypeError: 'NoneType' object is not callable
? 函数范围内有什么不同?如何解决?
import requests
from bs4 import BeautifulSoup
def findDiv(soup):
print soup.body.FindAll("div")
r = requests.get("http://google.com")
soup = BeautifulSoup(r.content)
print soup.findAll("div")
findDiv(soup)
问题出在FindAll
。 这不是一种方法。 尝试使用小写形式的findAll
代替。
def findDiv(soup):
print soup.body.findAll("div")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.