title: Filtering URLs obtained using BeautifulSoup
body: <p>I'm writing a program and the goal is to get the captions of links from a website, but only if that link is to certain website.</p>
  
  <p>I can, so far, use BeautifulSoup to grab a list of the anchor tags on the page (including the href="url" bits) and I'd like to filter them out, preferably with a regex.</p>
  
  <p>The links I want to grab are in the format: "<a href="http://section.website.com/123456" rel="nofollow">http://section.website.com/123456</a>" where 123456 is any 6 digit number. I have tried the code underneath, but nothing is appended to the data array.</p>
  
  <pre><code>import urllib2
  from BeautifulSoup import BeautifulSoup
  import re
  
  opener = urllib2.build_opener()
  opener.addheaders = [('User-agent', 'Mozilla/5.0')]
  
  url = ('http://awebsite.com')
  
  ourUrl = opener.open(url).read()
  
  soup = BeautifulSoup(ourUrl)
  
  links = soup.findAll('a')
  data = []
  for i in links:
      print i
  for i in links:
      if "http://section.website.com/\d+" in i:
          data.append(i.text)
  for entry in data:
      print entry
  
  raw_input()
  </code></pre>