I have written a function to create dynamic files and the file name will contain u 2 arguments that are passed to the function.
def formrequests(carrier,airport):
s=requests.Session()
r=s.get("http://www.transtats.bts.gov/Data_Elements.aspx?Data=2")
soup=BeautifulSoup(r.text)
viewstate_element=soup.find(id="__VIEWSTATE")
viewstate=viewstate_element["value"]
eventvalidation_element=soup.find(id="__EVENTVALIDATION")
eventvalidation=eventvalidation_element["value"]
r = s.post("https://www.transtats.bts.gov/Data_Elements.aspx?Data=2",
data = (
("__EVENTTARGET", ""),
("__EVENTARGUMENT", ""),
("__VIEWSTATE", viewstate),
("__EVENTVALIDATION", eventvalidation),
("CarrierList", carrier),
("AirportList", airport),
("Submit", "Submit")
)
)
f=open("C:\\Users\\JAYASHREE\\Desktop\\Data Analyst Nanodegree\\Data Wrangking with MongoDB\\carrier-airport data files\\%s-%s.html","w" %(carrier,airport))
f.write(r.text)
While running this function it is throwing me the following error:
TypeError Traceback (most recent call last)
<ipython-input-64-3323d46461b0> in <module>()
3 for carrier in carriers:
4 for airport in airports:
----> 5 formrequests(carrier,airport)
<ipython-input-63-258f8611f601> in formrequests(carrier, airport)
17 ("Submit", "Submit")
18 ))
---> 19 f=open("C:\\Users\\JAYASHREE\\Desktop\\Data Analyst Nanodegree\\Data Wrangking with MongoDB\\carrier-airport data files\\%s-%s.html","w" %(carrier,airport))
20 f.write(r.text)
TypeError: not all arguments converted during string formatting
Please let me know how to solve it.