如何解决属性错误:';非类型';对象没有属性';编码';用python
我得到的错误是:如何解决属性错误:';非类型';对象没有属性';编码';用python,python,file,beautifulsoup,Python,File,Beautifulsoup,我得到的错误是: for comment_entry in comment_feed.entry: content = comment_entry.ToString() parse = BeautifulSoup(content) for con in parse.find('ns0:content'): print con.string s = con.string file.write(s.encode('utf8')) 您的s可能是非类型 试一试 print co
for comment_entry in comment_feed.entry:
content = comment_entry.ToString()
parse = BeautifulSoup(content)
for con in parse.find('ns0:content'):
print con.string
s = con.string
file.write(s.encode('utf8'))
您的
s
可能是非类型
试一试
print con.string为您提供了什么
File "channel_search.py", line 108, in youtube_search
file.write(s.encode('utf8'))
AttributeError: 'NoneType' object has no attribute 'encode'
s = con.string
if s:file.write(s.encode('utf8'))
# or if s is not None
#if you want to check only for None