title: Python + BeautifulSoup: How to get ‘href’ attribute of ‘a’ element?
body: <p>I have the following:</p>
  
  <pre><code>  html =
    '''&lt;div class=“file-one”&gt;
      &lt;a href=“/file-one/additional” class=“file-link"&gt;
        &lt;h3 class=“file-name”&gt;File One&lt;/h3&gt;
      &lt;/a&gt;
      &lt;div class=“location”&gt;
        Down
      &lt;/div&gt;
    &lt;/div&gt;'''
  </code></pre>
  
  <p>And would like to get just the text of <code>href</code> which is <code>/file-one/additional</code>. So I did: </p>
  
  <pre><code>from bs4 import BeautifulSoup
  
  soup = BeautifulSoup(html, 'html.parser')
  
  link_text = “”
  
  for a in soup.find_all(‘a’, href=True, text=True):
      link_text = a[‘href’]
  
  print “Link: “ + link_text
  </code></pre>
  
  <p>But it just prints a blank, nothing. Just <code>Link:</code>. So I tested it out on another site but with a different HTML, and it worked. </p>
  
  <p>What could I be doing wrong? Or is there a possibility that the site intentionally programmed to not return the <code>href</code>? </p>
  
  <p>Thank you in advance and will be sure to upvote/accept answer!</p>