I want to scrape this website: any thoughts?
CodePudding user response:
Your cookie issue falls on this line:
csrf_token = s.get(URL).cookies["PHPSESSID"] # CAUSES ERROR
The cookie issue can be fixed with this:
import requests
URL = "https://dbh.smartschool.be"
s = requests.Session()
response = s.get(URL)
csrf_token = s.cookies.get_dict()['PHPSESSID']
print(csrf_token)
OUTPUT:
0ss1g37jsa5sg2sd2beu91vnqc8vamv3bmi03lmfc0p9c8kai3
If I leave out PHPSESSID
: and print the dictionary instead like this:
csrf_token = s.cookies.get_dict()
print(csrf_token)
OUTPUT:
{'PHPSESSID': '0ss1g37jsa5sg2sd2beu91vnqc8vamv3bmi03lmfc0p9c8kai3', 'pid': 'e2163707-0803-49c8-af39-f8c499508845'}