title: KeyError while accessing attributes of tags that exist - BeautifulSoup
body: <p>The version of my python is 2.7</p>
  
  <pre><code># -*- coding : utf - 8 -*-
  import urllib
  from bs4 import BeautifulSoup
  
  resp = urllib.urlopen('https://movie.douban.com/nowplaying/hangzhou')
  html_data = resp.read().decode('utf-8')
  
  soup = BeautifulSoup(html_data,'html.parser')
  nowplaying_movie = soup.find_all('div',id = 'nowplaying')
  print nowplaying_movie
  # notice class_
  nowplaying_movie_list = nowplaying_movie[0].find_all('li',class_ = 'list-item')
  print nowplaying_movie_list
  
  nowplaying_list = []
  for item in nowplaying_movie_list :
      nowplaying_dict = {}
      nowplaying_dict['id'] = item['id']
      nowplaying_dict['name'] = item['data-title']
      nowplaying_movie_list.append(nowplaying_dict)
  </code></pre>
  
  <p>And the printed-out content of nowplaying_movie_list is </p>
  
  <pre><code>[&lt;li class="list-item" data-actors="\u53e4\u5929\u4e50 / \u5434\u6a3e / \u6258\u5c3c\xb7\u8d3e" data-category="nowplaying" data-director="\u53f6\u4f1f\u4fe1" data-duration="101\u5206\u949f" data-enough="True" data-region="\u9999\u6e2f \u4e2d\u56fd\u5927\u9646" data-release="2017" data-score="7.5" data-showed="True" data-star="40" data-subject="26826398" data-title="\u6740\u7834\u72fc\xb7\u8d2a\u72fc" data-votecount="11357" id="26826398"&gt;\n&lt;ul class=""&gt;\n&lt;li class="poster"&gt;\n&lt;a class="ticket-btn" data-psource="poster" href="https://movie.douban.com/subject/26826398/?from=playing_poster" target="_blank"&gt;\n&lt;img alt="\u6740\u7834\u72fc\xb7\u8d2a\u72fc" class="" rel="nofollow" src="https://img3.doubanio
  </code></pre>
  
  <p>which I think is quite normal.</p>
  
  <p>I want to extract the id and name of movies on the website and save them into a dict, however error indicates something wrong with the 'data-title'. </p>
  
  <p>The error is </p>
  
  <blockquote>
    <p>Traceback (most recent call last):   File "C:/Python27/movie
    comments.py", line 19, in </p>
    
    <p>nowplaying_dict['name'] = item['data-title'] </p>
    
    <p>KeyError: 'data-title'</p>
  </blockquote>
  
  <p>I guess it is the problem of recognizing the <code>hyphen</code>, as I am pretty sure there exists the class "data-title" in the printed html file.</p>
  
  <p>Any thoughts would be helpful.</p>