title: Trying to grab just absolute links from a webpage using BeautifulSoup
body: <p>I am reading the contents of a webpage using BeautifulSoup. What I want is to just grab the <code>&lt;a href&gt;</code> that start with <code>http://</code>. I know in beautifulsoup you can search by the attributes. I guess I am just having a syntax issue. I would imagine it would go something like.</p>
  
  <pre><code>page = urllib2.urlopen("http://www.linkpages.com")
  soup = BeautifulSoup(page)
  for link in soup.findAll('a'):
      if link['href'].startswith('http://'):
          print links 
  </code></pre>
  
  <p>But that returns:</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;stdin&gt;", line 2, in &lt;module&gt;
    File "C:\Python26\lib\BeautifulSoup.py", line 598, in __getitem__
      return self._getAttrMap()[key]
  KeyError: 'href'
  </code></pre>
  
  <p>Any ideas? Thanks in advance.</p>
  
  <p><em>EDIT</em>
  This isn't for any site in particular. The script gets the url from the user. So internal link targets would be an issue, that's also why I only want the <code>&lt;'a'&gt;</code> from the pages. If I turn it towards <code>www.reddit.com</code>, it parses the beginning links and it gets to this:</p>
  
  <pre><code>&lt;a href="http://www.reddit.com/top/"&gt;top&lt;/a&gt;
  &lt;a href="http://www.reddit.com/saved/"&gt;saved&lt;/a&gt;
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 2, in &lt;module&gt;
    File "C:\Python26\lib\BeautifulSoup.py", line 598, in __getitem__
      return self._getAttrMap()[key]
  KeyError: 'href'
  </code></pre>