Skip to content

Instantly share code, notes, and snippets.

@matty234
Created June 10, 2021 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matty234/b82c309f16a7dd84a71c8bf340ba9237 to your computer and use it in GitHub Desktop.
Save matty234/b82c309f16a7dd84a71c8bf340ba9237 to your computer and use it in GitHub Desktop.
import requests
from bs4 import BeautifulSoup
headers = {}
url = "https://www.gov.uk/guidance/red-amber-and-green-list-rules-for-entering-england"
req = requests.get(url, headers)
soup = BeautifulSoup(req.content, 'html.parser')
lists = {}
tables = soup.findAll( "table" )
for table in tables:
head = table.find("thead").select("th")[0].getText().strip()
if head.endswith("list"):
splat = head.split(' ')[0]
found = []
countryGroup = table.find("tbody").select("tr")
for c in countryGroup:
val = c.select("th")[0].getText().strip()
print(val)
found.append(val)
lists[splat.lower()]=found
print(lists)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment