python-requests不抢JSESSIONID

python-requests does not grab JSESSIONID

我正在尝试使用请求来抓取网站。但是,我需要使用的 post 方法需要下面的 headers 。除了 JSESSION ID,我可以填写所有内容。让这个 post 方法起作用的唯一方法是,如果我手动进入浏览器,启动 session 并检查页面以检索 JSESSIONID。

我正在寻找一种使用 python 中的请求包检索此 JSESSIONID 的方法。我看到了一些使用 session 的建议。但是,请求 session 没有获取 JSESSIONID,这是我唯一需要的。我应该如何寻求可能的解决方案?

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=;

我目前尝试的是使用请求包中的 session,它应该存储 session 的 cookie。但是,在我使用 .get 方法后 requests.cookies 没有存储 JSESSIONID

query = 'Example%20query'
s = requests.Session()
suggest = s.get(f'https://www.examplewebsite.nl/api_route/suggest?query={query}').json()
s.cookies

首先转到 https://www.examplewebsite.nl 页面时生成 JSESSIONID。

import requests


query = 'Example%20query'
s = requests.Session()
s.get('https://www.examplewebsite.nl')
suggest = s.get(f'https://www.examplewebsite.nl/api_route/suggest?query={query}').json()
print(s.cookies.get("JSESSIONID"))