Jun-04-2020, 05:11 PM
Hi everyone. I have been trying to scrape a website to get the data of the next day. https://www.powerexindia.com/code/fronte...rice.html/. I am sending the correct data in POST request but still i am getting the webpage of current date. There is only error if I do not send the csrftoken otherwise no matter what date i send i am getting the webpage of current date data. Please help in knowing where i am wrong.
with requests.Session() as session:
try:
res = session.get(self.BASE_URL, headers=headers)
except requests.exceptions.Timeout as e:
print(standard_datetime(), FILENAME, date, e)
else:
csrf = res.cookies.get("csrftoken")
if csrf is None:
return None
headers.update({"X-CSRFToken": csrf})
cookies = {"csrftoken": csrf}
payload = {
"dataview12": "Daily",
"fromhour": "0",
"tohour": "95",
"DeliveryDate": "2020-06-07",
"csrfmiddlewaretoken": csrf,
"markall": "%",
"N1": "N1", "N2": "N2", "N3": "N3",
"E1": "E1", "E2": "E2",
"W1": "W1", "W2": "W2", "W3": "W3",
"S1": "S1", "S2": "S2", "S3": "S3",
"A1": "A1", "A2": "A2",
"DeliveryfromDate": "", "DeliverytoDate": "",
"year": "2020", "month": "1",
"submit": "submit"
}
print(payload)
try:
res = session.post(
self.BASE_URL, headers=headers, cookies=cookies
)
except requests.exceptions.Timeout as e:
print(standard_datetime(), FILENAME, date, e)
except requests.exceptions.SSLError as e:
print(standard_datetime(), FILENAME, date, e)
except requests.exceptions.ConnectionError as e:
print(standard_datetime(), FILENAME, date, e)
else:
return res
