我有一个包含以下两个函数的脚本:
# Getting content of each page
def GetContent(url):
response = requests.get(url)
return response.content
# Extracting the sites
def CiteParser(content):
soup = BeautifulSoup(content)
print "---> site #: ",len(soup('cite'))
result = []
for cite in soup.find_all('cite'):
result.append(cite.string.split('/')[0])
return result
当我运行程序时,出现以下错误:
result.append(cite.string.split('/')[0])
AttributeError: 'NoneType' object has no attribute 'split'
输出样例:
URL: <URL That I use to search 'can be google, bing, etc'>
---> site #: 10
site1.com
.
.
.
site10.com
URL: <URL That I use to search 'can be google, bing, etc'>
File "python.py", line 49, in CiteParser
result.append(cite.string.split('/')[0])
AttributeError: 'NoneType' object has no attribute 'split'
cite.string
返回了一个NoneType
。 - cppcodercite.string
具有适当的值。在应用split
函数之前进行验证。 - cppcodercite
对象以及cite.string
返回的内容是什么。 - cppcoder<cite></cite>
的标签。它返回的是site1.com到site10.com
。 - MLSC