title: How to get the URL of an HTML href Attribute containing an .ics file with Python?
body: <p>I am trying to get the URL of an <code>.ics</code> file off of a webpage containing an <code>.ics</code> calendar. For example, <a href="https://meded.hms.harvard.edu/calendar" rel="nofollow noreferrer">https://meded.hms.harvard.edu/calendar</a>, but it should work for any webpage containing <code>.ics</code>.
  Below is my naive attempt (which doesn't print anything and I can't figure out why):</p>
  
  <pre><code>import urllib2
  import requests
  import bs4
  
  def get_ics_url(url):
  
      #page = requests.get('https://meded.hms.harvard.edu/calendar').content
  
      page = requests.get(url).content
      soup = bs4.BeautifulSoup(page, 'lxml')
  
      links = soup.find_all('a')
  
      for link in links:
          if link.get('href')[-4:]=='.ics':
              endout = type(link.get('href'))
  
              print endout
          break
  </code></pre>
  
  <p>What am I doing wrong, and what is a better way to obtain the URL of an <code>.ics</code> file that I'm looking for?</p>