我写了一个函数来创建动态文件,文件名将包含传递给函数的u2参数。在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)
运行此函数时,它向我抛出以下错误:
^{pr2}$
请告诉我怎么解决它。在