gpt4 book ai didi

python - 类型错误 : 'NoneType' object is not callable, BeautifulSoup

转载 作者:太空宇宙 更新时间:2023-11-03 13:00:56 34 4
gpt4 key购买 nike

我遇到了一个奇怪的错误。我正在尝试做一些基本的解析。本质上,我正在以“x”格式收集数据,并希望以我可以使用的格式返回所有内容。我的直接问题是我的代码返回了一个奇怪的错误。我已经查看了此处针对同一问题的其他一些帖子/答案,但断章取意……确实很难查明问题所在。

data = url.text

soup = BeautifulSoup(data, "html5lib")

results = [] # this is what my result set will end up as

def parseDiv(text):
#function takes one input parameter - a single div for which it will parse for specific items, and return it all as a dictionary
soup2 = BeautifulSoup(text)
title = soup2.find("a", "yschttl spt")
print title.text
print

return title.text

for result in soup.find_all("div", "res"):
"""
This is where the data is first handled - this would return a div with links, text, etc -
So, I pass the blurb of text into the parseDiv() function
"""
item = parseDiv(result)
results.append(item)

显然,在这一点上,我已经包含了我需要的库...当我提取 soup2 的代码(bs4 的第二个实例在我要处理的新文本简介上)时,只打印我的函数的输入, 一切正常。

这里是错误:

Traceback (most recent call last):
File "testdata.py", line 29, in <module>
item = parseDiv(result)
File "testdata.py", line 17, in parseDiv
soup2 = BeautifulSoup(text)
File "C:\Python27\lib\site-packages\bs4\__i
markup = markup.read()
TypeError: 'NoneType' object is not callable

最佳答案

您不需要再次解析 div。试试这个:

for div in soup.find_all('div', 'res'):
a = div.find('a', 'yschttl spt')
if a:
print a.text
print
results.append(a)

关于python - 类型错误 : 'NoneType' object is not callable, BeautifulSoup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21696264/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com