I am trying to access snowdaypredictor.com to get the chance of a snowday for a school project, the site does not automatically show the chance of a snowday as it has to load. I have tried the below code, but it hasn't worked. Is there anyway to wait before reading the data of a URL?
import urllib2
import time
url = 'http://snowdaypredictor.com%20%22SnowdayPredictor.com'
data = urllib2.urlopen(url)
time.sleep(10)
data = data.read()
The data you want actually isn't at the URL you think it is. The page makes a subsequent request to another URL which returns the data about snowfall and snow day percentage, and then a script in the first page does the nice little counting up animation with that data. This actually makes it extremely easy for you to get the data; here's an example:
https://api.snowdaypredictor.com/query/80424
Edit:
So I just tried this in python, and for some reason it was giving me an SSL error. You can use requests
instead of urllib2
(You'll need to pip install
it) to get by this, by using the verify=False flag. Here's some example code that gets the percentage for Breckenridge, CO and prints it. You can safely ignore the warning (it seems that snowdaypredictor doesn't have its SSL certificates configured correctly:
>>> import requests
>>> requests.get('https://api.snowdaypredictor.com/query/80424', verify=False).json()['percent']
/usr/local/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py:838: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/security.html
InsecureRequestWarning)
14