WIP Changed cookies.

This commit is contained in:
Naida Vatric
2020-01-13 11:02:26 +01:00
parent e70901d369
commit ba43fa0713

View File

@@ -587,17 +587,21 @@ class ProstorCrawler {
} }
async loginForScraping(PROSTOR_LOGIN) { async loginForScraping(PROSTOR_LOGIN) {
console.log("PROSTOR_LOGIN", PROSTOR_LOGIN); console.log("PROSTOR_LOGIN", PROSTOR_LOGIN);
var formData = new FormData(); const prostorCookie = await this.getCookies();
console.log("prostor cookie", prostorCookie);
let formData = new FormData();
formData.append("email", PROSTOR_LOGIN.EMAIL); formData.append("email", PROSTOR_LOGIN.EMAIL);
formData.append("password", PROSTOR_LOGIN.PASSWORD); formData.append("password", PROSTOR_LOGIN.PASSWORD);
//When once loged in it stays loged in with same credentials. //When once loged in it stays loged in with same credentials.
//Do we need to log out ?? //Do we need to log out ??
return fetch("https://prostor.ba/moj-prostor/prijava", { return fetch("https://prostor.ba/moj-prostor/prijava", {
method: "POST", method: "POST",
body: formData, body: formData,
headers: { Cookie: "ci_session=3a47b6e18b3b9bc146bcde1f95126cbad0f58bf7" } headers: { Cookie: prostorCookie }
}) })
.then(page => { .then(page => {
//
console.log("headers: ", page.headers.raw()["set-cookie"]);
return page.text(); return page.text();
}) })
.then(resp => { .then(resp => {
@@ -619,6 +623,20 @@ class ProstorCrawler {
console.log("[PROSTOR]: Crawler login error ", err); console.log("[PROSTOR]: Crawler login error ", err);
}); });
} }
async getCookies() {
const getResponse = await fetch("https://prostor.ba/moj-prostor/prijava", {
headers: { Cookie: "" }
});
const raw = getResponse.headers.raw()["set-cookie"];
const cookie = raw
.map(datastring => {
const data = datastring.split(";");
const cookieData = data[0];
return cookieData;
})
.join(";");
return cookie;
}
} }
module.exports = ProstorCrawler; module.exports = ProstorCrawler;