I'm trying to scrape results from this booking website. In the POST request
in addition to the trip codes and date, there is also _csrf
parameter which I assume is a CSRF token
.
I've tried to get the session cookie and extract the CSRF token
following this answer but the cookie I get back has no CSRF token
<RequestsCookieJar[<Cookie JSESSIONID=W33kBCH5zFsyVhTyQL9L4Ibyq-KLGTBSD4h_IUNA.aru-270545 for www.booking.alilaurogruson.it/booking>]>
def get_session_cookie():
url = 'https://www.booking.alilaurogruson.it/booking/welcome/home'
s = requests.Session()
s.get(url, verify=False)
print(s.cookies)
if 'csrftoken' in s.cookies:
# Django 1.6 and up
csrftoken = s.cookies['csrftoken']
else:
# older versions
csrftoken = s.cookies['csrf']
return csrftoken
How can I successfully scrape the search results?