'Python requests - POST request - payload not working
I'm trying to retrieve data sets based on a list of dates with POST requests, however, the request seems to return the same data despite my code below changing the dates on each loop.
I've confirmed that the dates are changing correctly as per the loop.
I believe the issue is relating to the payload but I can't figure out why.
Here is a snippet of the payload from the website:
for date in range(1,5,2):
#enter dates in format YYYYMMDD
Bdate = dates[date-1]
Adate = dates[date]
#Prepare the column headers
BdateVal = Bdate + " Est. value ($m)"
AdateVal = Adate + " Est. value ($m)"
#retrive payload and enter index + dates
d = {"__EVENTTARGET":"m$m$p1$p1$ITrakResults$DownloadButtoniTrak", "__EVENTARGUMENT":"","__LASTFOCUS":"", "__VIEWSTATE":VS ,
"__VIEWSTATEGENERATOR":VSG , "__SCROLLPOSITIONX":"0","__SCROLLPOSITIONY":"400",
"m$m$p1$p1$ITrakFilter$ddlInvestmentIn":options[1],"m$m$p1$p1$ITrakFilter$ddlComparisonPeriod":Bdate,
"m$m$p1$p1$ITrakFilter$HiddenFieldLatterDate":Adate,"m$m$p1$p1$ITrakFilter$txtInvestorName":"",
"m$m$p1$p1$ITrakFilter$ddlInvestmentStyle":"","m$m$p1$p1$ITrakFilter$ddlInvestorList":"All Company Lists",
"m$m$p1$p1$ITrakFilter$ddlInvestmentTrends":"0","m$m$p1$p1$ITrakFilter$slider_min":"0",
"m$m$p1$p1$ITrakFilter$slider_max":"71000","m$m$p1$p1$ITrakFilter$txtSliderLeftValue":"0",
"m$m$p1$p1$ITrakFilter$txtSliderRightValue":"71000","m$m$p1$p1$ITrakFilter$ucLocation$Location":"RadioButtonLocationIgnore",
"m$m$p1$p1$ITrakFilter$ucLocation$DropDownRegions":"0","m$m$p1$p1$ITrakFilter$ucLocation$DropDownCountries":"0"}
#Post the request
GetCSV = s.post("some website",headers=EFSHeaders, data=d)
#convert into a dataframe
xlsx = pd.read_excel(GetCSV.content, skiprows=0)
#Grab the index
index = xlsx.iat[1,1]
#Convert into our dataframe
insto["investor"] = xlsx.iloc[11:,0]
insto["location"] = xlsx.iloc[11:,2]
insto["style"] = xlsx.iloc[11:,3]
insto["index"] = index
insto[AdateVal] = xlsx.iloc[11:,4]
insto[BdateVal] = xlsx.iloc[11:,9]
#format and convert to $m
Currency_columns = [AdateVal,BdateVal]
for cols in Currency_columns:
insto[cols] = pd.to_numeric(insto[cols], downcast="float")
insto[cols] = insto[cols].div(1000000).round(1)
insto[cols] = insto[cols].map("${:,.2f}".format)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

