1

I'm trying to make a small Snow Day Calculator python program, and I figured that I could use BeautifulSoup to do the job. I am able to successfully scrape the page, HOWEVER I noticed that the result is always 0%. I then noticed that this is because it takes the website about a second or two after it loads to display the percentage, and this is because of the website's reactive javascript.

How would I be able to load the webpage, wait two-three seconds, and then scrape the webpage for the snow day percentage?

Code:

import urllib
import bs4

def getPercent(zip):
    url = "https://snowdaypredictor.com/result.html?q="+zip
    print url
    page = urllib.urlopen(url)
    soup = bs4.BeautifulSoup(page,'html.parser')
    name_box = soup.find('span', attrs = {'id': 'result-percent'})
    print name_box.text.strip(),"%"

getPercent(raw_input("What is your zip code?"))
Davis Keene
  • 213
  • 1
  • 5
  • 12

0 Answers0