I am new here and new at programming. I am trying to log in the URL='https://www.esselunga.it/area-utenti/applicationCheck?AppName=esselungaEcommerce&daru=https%3A%2F%2Fwww.esselungaacasa.it%3A443%2Fecommerce%2Fnav%2Fauth%2Fsupermercato%2Fhome.html%3F&loginType=light'.
When I inspect the webpage I clearly see the csrf_token in the HTML ('name'='X-CSRF-TOKEN') and its value; however when I extract it with BeautifulSoup it is not available. I checked the content (requests.session().get(url).content) the csrf_token lines disappeared, same in the 'View Page Source'.
Is it possible to retrieve the CSRF still, or is there anyway to log in without it?
thanks!
import requests
from bs4 import BeautifulSoup
## Here below the data collected from the Network source view, once i logged in. Form Data section:
login_data= {'username':'xxxx', # <- instead of xxx put your username
'password':'xxxx', # <- instead of xxx put your psswrd
'daru':'xxx', # <- data taken from the FORM DATA
'dare':'xxxx', # <- data taken from the FORM DATA
'appName': 'xxx'} # <- data taken from the FORM DATA
with requests.Session() as s:
login_url="xxx" #<- the URL is above in the comment
result = s.get(login_url)
print (result.content) # here you can see the X-CSRF-TOKEN is not extracted.
soup = BeautifulSoup(result.content,'html5lib')
p = soup.find('input', attrs={'name':'X-CSRF-TOKEN'})['value'] # I can see it in the inspection tab
print(p) # csrf token is not in the content, neither when i check the 'view page source'. But in the inspection I see it!
## I am stuck at the above line. The following would be:
login_data['X-CSRF-TOKEN']) = p
r = s.post(login_url,data=login_data)
print(r.content)