I'm trying to scrape a website using requests. However, a post method that I need to use requires the headers below. I can fill everything apart from the JSESSION ID. The only way I can get this post method to work is if I manually go into the browser, start a session and inspect the page to retrieve the JSESSIONID.
I am looking for a way to retrieve this JSESSIONID using the requests package in python. I saw some suggestions for using a session. However, the requests session does not grab the JSESSIONID, which is the only thing I need. How should I go about a possible solution?
Host:
Connection:
Content-Length:
Accept:
X-Requested-With:
User-Agent:
Content-Type:
Sec-GPC:
Origin:
Sec-Fetch-Site:
Sec-Fetch-Mode:
Sec-Fetch-Dest:
Referer:
Accept-Encoding:
Accept-Language:
Cookie: _1aa19=; JSESSIONID=;
What I currently tried is use a session from the requests package, which should store the cookies of the session. However, After I use a .get method requests.cookies does not have the JSESSIONID stored
query = 'Example query'
s = requests.Session()
suggest = s.get(f'https://www.examplewebsite.nl/api/geocoder/v3/suggest?query={query}').json()
s.cookies
CodePudding user response:
JSESSIONID is generated when you go to https://www.wozwaardeloket.nl
page first.
import requests
query = 'Example query'
s = requests.Session()
s.get('https://www.wozwaardeloket.nl')
suggest = s.get(f'https://www.wozwaardeloket.nl/api/geocoder/v3/suggest?query={query}').json()
print(s.cookies.get("JSESSIONID"))