I am trying to scrape a webpage using python but in order to scrape the webpage , I need to accept cookies on the webpage.
The code which I have tried is
URL = "https://www.howoge.de/wohnungen-gewerbe/wohnungssuche.html"
with open('cookies') as f:
j = json.load(f)
session = requests.Session()
for cookie in j: session.cookies.set(cookie['name'], cookie['value'])
r = session.get(URL)
though this is not raising any error but still not accepting the cookies.
Here are my cookies:
[
{
"domain": ".howoge.de",
"expirationDate": 1694266885,
"hostOnly": false,
"httpOnly": false,
"name": "__cmpcpcu10543",
"path": "/",
"sameSite": "no_restriction",
"secure": true,
"session": false,
"storeId": null,
"value": "__51_54__"
},
{
"domain": ".howoge.de",
"expirationDate": 1694266885,
"hostOnly": false,
"httpOnly": false,
"name": "__cmpconsent10543",
"path": "/",
"sameSite": "no_restriction",
"secure": true,
"session": false,
"storeId": null,
"value": "BPfEJk4PfEJk4AfHIBDEDXAAAAAAAA"
},
{
"domain": "www.howoge.de",
"expirationDate": 1696858880,
"hostOnly": true,
"httpOnly": false,
"name": "__cmpcc",
"path": "/",
"sameSite": "no_restriction",
"secure": true,
"session": false,
"storeId": null,
"value": "1"
},
{
"domain": ".howoge.de",
"expirationDate": 1694266885,
"hostOnly": false,
"httpOnly": false,
"name": "__cmpcvcu10543",
"path": "/",
"sameSite": "no_restriction",
"secure": true,
"session": false,
"storeId": null,
"value": "__s974_U__"
},
{
"domain": "www.howoge.de",
"hostOnly": true,
"httpOnly": false,
"name": "PHPSESSID",
"path": "/",
"sameSite": null,
"secure": false,
"session": true,
"storeId": null,
"value": "8pnd5h5up4v4rjh498if7hedac"
}
]
What should be the best approach to tackle this problem?