import requests from bs4 import BeautifulSoup import json html_page = "page_source.html" def extract_data(page): data = {"eventvalidation":"", "viewstate": ""} with open(page, "r") as html; soup = BeautifulSoup(html, "lxml") ev = soup.find(id="__EVENTVALIDATION") data["eventvalidation"] = ev["value"] vs = soup.find(id="__VIEWSTATE") data["viewstate"] = vs["value"] return data def make_request(data): eventvalidation = data["eventvalidation"] viewstate = data["viewstate"] r = requests.post("http://www.transtats.bts.gov/Data_Elements.aspx?Data=2", data={'AirportList' : "BOS", 'CarrierList' : "VX", 'Submit' : "Submit", '__EVENTTARGET' : "", '__EVENTARGUMENT' : "", '__EVENTVALIDATION' : eventvalidation, '__VIEWSTATE' : viewstate}) return r.text def test():