title: Python Beautiful Soup 'NoneType' object error
body: <p>I am using Beautiful Soup to get hyperlinks in the body of web pages. Here is the code I use</p>
  <pre><code>import urllib2
  from bs4 import BeautifulSoup
  
  url = 'http://www.1914-1918.net/swb.htm'
  element = 'body'
  request = urllib2.Request(url)
  page = urllib2.urlopen(request).read()
  pageSoup = BeautifulSoup(page)
  for elementSoup in pageSoup.find_all(element):
    for linkSoup in elementSoup.find_all('a'):
      print linkSoup['href']
  </code></pre>
  <p>I got an AttributeError when I tried to find hyperlinks for the swb.htm page.</p>
  <p>AttributeError: 'NoneType' object has no attribute 'next_element'</p>
  <p>I am sure that there are a body element and a couple of 'a' elements under the body element. But strangely it works well for other pages (e.g. <a href="http://www.1914-1918.net/1div.htm" rel="nofollow noreferrer">http://www.1914-1918.net/1div.htm</a>).</p>
  <p>This problem has been haunting me for days. Can anyone please point out what I did wrong.</p>
  <p>Screenshot</p>
  <p><img src="https://i.stack.imgur.com/K6W0E.jpg" alt="enter image description here" /></p>