python 使用dir打印出来的方法,调用一直报错?

qq_38741240 2017-09-26 03:27:15
soup = BeautifulSoup(data['body'], "html.parser")
nowplaying_movie = soup.find_all('table', id="ip_list")
nowplaying_movie_list = nowplaying_movie[0].find_all('tr')

for items in nowplaying_movie_list:
#item=items.find_all('tr');
country = items.find(attrs={'class':'country'});
#if(country!='国家' and country!=''):
# print(items);
print(country.get_text())
print('------------')



我dir(country)打印里面有哪些方法,发现有get_text,然后我就用country.get_text()却报错(使用country.get_text也不行),我该如何调用dir打印出来的方法呢

报错信息 AttributeError: 'NoneType' object has no attribute 'get_text'
dir(country)出来的部分数据:

'append', 'attribselect_re', 'attrs', 'can_be_empty_element', 'childGenerator', 'children', 'clear', 'contents', 'decode', 'decode_contents', 'decompose', 'descendants', 'encode', 'encode_contents', 'extract', 'fetchNextSiblings', 'fetchParents', 'fetchPrevious', 'fetchPreviousSiblings', 'find', 'findAll', 'findAllNext', 'findAllPrevious', 'findChild', 'findChildren', 'findNext', 'findNextSibling', 'findNextSiblings', 'findParent', 'findParents', 'findPrevious', 'findPreviousSibling', 'findPreviousSiblings', 'find_all', 'find_all_next', 'find_all_previous', 'find_next', 'find_next_sibling', 'find_next_siblings', 'find_parent', 'find_parents', 'find_previous', 'find_previous_sibling', 'find_previous_siblings', 'format_string', 'get', 'getText', 'get_attribute_list', 'get_text', 'has_attr', 'has_key', 'hidden', 'index', 'insert', 'insert_after', 'insert_before', 'isSelfClosing', 'is_empty_element', 'known_xml', 'name', 'namespace', 'next', 'nextGenerator', 'nextSibling', 'nextSiblingGenerator', 'next_element', 'next_elements', 'next_sibling', 'next_siblings', 'parent', 'parentGenerator', 'parents', 'parserClass', 'parser_class', 'prefix', 'preserve_whitespace_tags', 'prettify', 'previous', 'previousGenerator', 'previousSibling', 'previousSiblingGenerator', 'previous_element', 'previous_elements', 'previous_sibling', 'previous_siblings', 'quoted_colon', 'recursiveChildGenerator', 'renderContents', 'replaceWith', 'replaceWithChildren', 'replace_with', 'replace_with_children', 'select', 'select_one', 'setup', 'string', 'strings', 'stripped_strings', 'tag_name_re', 'text', 'unwrap', 'wrap']
...全文
189 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
cnaaa8 2017-10-31
  • 打赏
  • 举报
回复
判断下none
jxxx2967 2017-09-27
  • 打赏
  • 举报
回复
报错信息 AttributeError: 'NoneType' object has no attribute 'get_text' 错误写得挺清楚的,country 现在是 None

37,718

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧