找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 3175|回复: 0

[讨论] python 使用dir打印出来的方法,调用一直报错

2

主题

2

帖子

2

积分

贫民

积分
2
3044708989 发表于 2017-9-26 16:32:16 | 显示全部楼层 |阅读模式


  1. soup = BeautifulSoup(data['body'], "html.parser")
  2. nowplaying_movie = soup.find_all('table', id="ip_list")
  3. nowplaying_movie_list = nowplaying_movie[0].find_all('tr')

  4. for items in nowplaying_movie_list:
  5. #item=items.find_all('tr');
  6. country = items.find(attrs={'class':'country'});
  7. #if(country!='国家' and country!=''):
  8.      #   print(items);
  9. print(country.get_text())
  10.     print('------------')
复制代码





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

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

  1. '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']
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表