Project Brief
Your task for this project is to write a Python script that scrapes the temperature from the following page every minute:
https://forecast.weather.gov/MapClick.php?lat=40.7146&lon=-74.0071
Here is what the webpage looks like. The highlighted text is the value you need to scrape.
Expected Output
Once executed, the program should run continuously scraping the temperature value every minute and printing it out on the command line:
Environment Setup Instructions
Install the required libraries.
pip install beautifulsoup4 requests schedule
Run the app with python main.py
Resources
Learn how to use BeautifulSoup and requests to scrape text from a webpage:
https://pythonhow.com/how/scrape-a-wikipedia-page/
Learn how to use the schedule library to schedule Python code:
https://schedule.readthedocs.io/en/stable/
I decided to make a version of mine using regex instead of beautifulsoup:
temp_f = re.search("myforecast-current(.+?)>(.+?)°F", response.text)
temp_c = re.search("myforecast-current(.+?)>(.+?)°C", response.text)
print("The temperature in", place, "at", time.asctime() ,"is:")
print(temp_f.group(2), "F /", temp_c.group(2), "C") #with 2 wildcard queries, the temperature is in the second group as returned by re.search()