I have tried using get requests with params, post requests with and without json.dumps but I can not seem to get the right response from the webpage.
I want to get back a text file with all the weather data. My code, the data I want, and the headers for the post request using the inspect on chrome is attached.
Thank you for any help!
You can also reach the data by
- going to http://climod2.nrcc.cornell.edu
- click on daily data listing
- input dates from 6/1/18 to current date
- check csv instead of html
then type NY City Central Park for the station selection which will return search results with that station then click go.
Below are the screenshots:
- Attempt
- Had to delete due to not being able to post more than 8 links.
- Headers
- Desired data
- Response Data `
from urllib.request import urlopen as uReq from bs4 import BeautifulSoup as soup import requests import datetime import json
payload = {'method': 'POST','params':{"elems":[{"name":"maxt","add":"t"}, {"name":"mint","add":"t"},{"name":"pcpn","add":"t"}, {"name":"snow","add":"t"},{"name":"snwd","add":"t"}],"sId":"94728 1","sDate":"2018-06-01","eDate":"2018-06-28"},'output':'json'}
parameters = {"elems":[{"name":"maxt","add":"t"},{"name":"mint","add":"t"}, {"name":"pcpn","add":"t"},{"name":"snow","add":"t"}, {"name":"snwd","add":"t"}],"sid":"94728 1","sDate":"2018-06- 01","eDate":"2018-06-28"}
headers = {'Accept': 'application/json, text/javascript, /; q=0.01','Content-Type': 'application/x-www-form-urlencoded; charset=UTF- 8','Origin': 'http://climod2.nrcc.cornell.edu','Referer':'http://climod2.nrcc.cornell.edu/elems=name&elems=add&elems=name&elems=add&elems=name&elems=add&elems=name&elems=add&elems=name&elems=add&sDate=2018-06-01&eDate=2018-06-28&meta=name&meta=state&meta=ll&meta=sids&bbox=-74.44262803978918&bbox=40.4207924883181&bbox=-73.4880821602','User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36'}
dataurl='https://data.rcc-acis.org/StnData'
r = requests.post(dataurl, data = json.dumps(payload), headers = headers)
print(r.status_code) print(r.elapsed) print(r.json) print(r.text)`