title: I want to exception handle 'list index out of range.'
body: <p>I am using <strong>BeautifulSoup</strong> and parsing some HTMLs.</p>
  
  <p>I'm getting a certain data from each HTML <em>(using for loop)</em> and adding that data to a certain list.</p>
  
  <p>The problem is, some of the HTMLs have different format <em>(and they don't have the data that I want in them)</em>.</p>
  
  <p>So, I was trying to use exception handling and add value <code>null</code> to the list <em>(I should do this since the sequence of data is important.)</em></p>
  
  <p>For instance, I have a code like:</p>
  
  <pre><code>soup = BeautifulSoup(links)
  dlist = soup.findAll('dd', 'title')
  # I'm trying to find content between &lt;dd class='title'&gt; and &lt;/dd&gt;
  gotdata = dlist[1]
  # and what i want is the 2nd content of those
  newlist.append(gotdata)
  # and I add that to a newlist
  </code></pre>
  
  <p>and some of the links don't have any <code>&lt;dd class='title'&gt;</code>, so what I want to do is add string <code>null</code> to the list instead.</p>
  
  <p>The error appears: </p>
  
  <pre><code>list index out of range.
  </code></pre>
  
  <p>What I have done tried is to add some lines like this:</p>
  
  <pre><code>if not dlist[1]:  
     newlist.append('null')
     continue
  </code></pre>
  
  <p>But it doesn't work out. It still shows error:</p>
  
  <pre><code>list index out of range.
  </code></pre>
  
  <p>What should I do about this? Should I use exception handling? or is there any easier way?</p>
  
  <p>Any suggestions? Any help would be really great!</p>