title: Get immediate parent tag with BeautifulSoup in Python
body: <p>I've researched this question but haven't seen an actual solution to solving this. I'm using BeautifulSoup with Python and what I'm looking to do is get all image tags from a page, loop through each and check each to see if it's immediate parent is an anchor tag.</p>
  
  <p>Here's some pseudo code:</p>
  
  <pre><code>html = BeautifulSoup(responseHtml)
  
  for image in html.findAll('img'):
      if (image.parent.name == 'a'):
           image.hasParent = image.parent.link
  </code></pre>
  
  <p>Any ideas on this?</p>