-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxml_scrape.py
More file actions
30 lines (25 loc) · 831 Bytes
/
Copy pathxml_scrape.py
File metadata and controls
30 lines (25 loc) · 831 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#Set up the template
template = 'https://www.ncdc.noaa.gov/cag/statewide/rankings/%s-tavg-%s%s/data.xml'
parameter = 'Average Temperature'
state = '44'
month = '08'
year = '2018'
URL = template % (state, year, month)
period = 4 #Apr-Aug 2018 code number
#Check to ensure it works
#print(URL)
#import packages
import requests
from lxml import objectify
#pull data and put it in correct format
response = requests.get(URL).content
root = objectify.fromstring(response)
#Check work
#print(response)
#Print out requested data for homework
print('W&M username: schojnicki')
print('Value: ', root.data[period].value)
print('Mean: ', root.data[period].mean)
print('Departure: ', root.data[period].departure)
print('Low Rank: ', root.data[period].lowRank)
print('High Rank: ', root.data[period].highRank)