Skip to content

Instantly share code, notes, and snippets.

@allyunion
Created January 30, 2021 02:23
Show Gist options
  • Save allyunion/1c006914f471fdc366273eec4b0e669c to your computer and use it in GitHub Desktop.
Save allyunion/1c006914f471fdc366273eec4b0e669c to your computer and use it in GitHub Desktop.
In [1]: import requests
In [2]: url = 'https://releases.hashicorp.com/terraform/'
In [3]: page = requests.get(url)
In [6]: from bs4 import BeautifulSoup as bs
In [7]: soup = bs(page.text, 'html.parser')
In [29]: for link in soup.find_all('a'):
...: if 'terraform' in link.text:
...: version = link.text.replace('terraform_', '')
...: subpage_url = str(urllib.parse.urljoin(url, link.get('href'))) + link.text + '_SHA256SUMS'
...: subpage = requests.get(subpage_url)
...: for line in subpage.text.split('\n'):
...: if 'linux_amd64' in line:
...: data[version] = 'sha256=' + line.split()[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment