Skip to content

Instantly share code, notes, and snippets.

@davidbb
Created April 13, 2019 23:52
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 davidbb/9be7193991da89b3748b925d4e88a9e3 to your computer and use it in GitHub Desktop.
Save davidbb/9be7193991da89b3748b925d4e88a9e3 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/python3.5
from bs4 import BeautifulSoup
import requests
import json
URL="https://weather.gc.ca/warnings/report_e.html?qc67"
raw_html = requests.get(URL).text
data = BeautifulSoup(raw_html, 'html.parser')
j=dict()
date="None"
details="No warnings in effect"
raw_title=data.select('.col-xs-12:nth-of-type(1) p:nth-of-type(1)')[0]
title=str(raw_title).split(">")[5].split("<")[0][:-5]
date = str(raw_title).split(">")[2].split("<")[0]
if "No Alerts in effect" in str(raw_title):
title = "No alerts in effect"
details = "No alerts in effect"
else:
try:
details = data.select('.col-xs-12:nth-of-type(1) p:nth-of-type(2)')[0].text
except:
print("Unable to get details for alert")
j["date"] = date
j["details"] = details
j["title"] = title
print(json.dumps(j))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment