繁体   English   中英

在函数中使用Beautiful Soup对象时,NoneType错误

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM