So I need to scrape this site, but everything is dynamic. I can't append to the URL the query param i need so i need to pass it with a POST request. I extracted the headers and the payload but something breaks along the way and i get the results of the starting page, not the page with the sent POST request. Also the JSESSION ID i get at the end is not the same as the one i sent in the headers. Here is my code
# post_URL = "https://lekovi.zdravstvo.gov.mk/drugsregister.searchform"
session = requests.Session()
cookie = session.get(URL).cookies.get("JSESSIONID")
print(cookie)
headers = {
"Accept": "text/javascript, text/html, application/xml, text/xml, */*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-MK,en-US;q=0.9,en-GB;q=0.8,en;q=0.7,mk;q=0.6",
"Connection": "keep-alive",
"Content-Length": "819",
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"Cookie": f"SERVERID=APPC_L2; JSESSIONID={cookie}",
"Host": "lekovi.zdravstvo.gov.mk",
"Origin": "https://lekovi.zdravstvo.gov.mk",
"Referer": "https://lekovi.zdravstvo.gov.mk/drugsregister/overview",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
"Sec-GPC": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.81 Safari/537.36",
"X-Prototype-Version": "1.7",
"X-Requested-With": "XMLHttpReques",
}
payload = {
"t:ac": "overview",
"t:submit": ["submit_3","submit_0"],
"t:formdata": "Db5ytL52OazQLgFwZVqY/TPR99w=:H4sIAAAAAAAAAJVSu0oDQRS9BoRAGhF8NWLho1sDmkYbY0QQYiIGa5md3F1HdmfWO7N5NFb+hI1fIFb6BRZ2/oMfYGNhZeFMshrFR7TaYc89c86dcy4fYbS9BAtblIZ6H0OhDdJaICL78bssSUi1WMQZkUDSBCVFoccSxo/QMyxBbahb8rgijITv+UyjV/btT8bNtsCoOd9AkyYLB7eFh4m7lxyMVKHAlTSkohqL0cB49Zi12HLEZLjcMCRkuN5JDEz1LWx2y5mFSt/Cf7yW/+t1jxRHrRupHwuthZK3V83V4PniPgfQSdpzMPtZOmYyDSw7JSRpt9EncApgYOwj4NYcTnXM0a9jDpJp7CMp4qo5UHBArQfUqWKB4dQfFEKUSIK7aUXM8HeFDHD261Q2fDi1r7AI898HFFsTKrAPmzLJ3zeZfAt618L1YCeD/3pNX3MaJj8PaxehOSzaFmz82gKu4kRJlEZ7vdjN1xKcN55mbq7PKjnIVSHPI2Gnd5pO2JUZI7TvbGpZhiOuvPlMfmVwLL4CyWl1EGkDAAA=",
"filterByApprovalCarrier": "",
"manufacturerName": "",
"nameNumberOrCode": "paracetamol", # This is the thing i'm searching for, its an input field
"genericNameOrAtc": "",
"filterByModeOfIssuance": "",
"t:zoneid": "gridZone,"
}
d = session.post(URL, headers=headers, data=payload)
print(d.cookies.get("JSESSIONID"))```