WIP Changed login to crawler.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
const fetch = require("node-fetch");
|
||||
const cheerio = require("cheerio");
|
||||
const moment = require("moment-timezone");
|
||||
const FormData = require("form-data");
|
||||
|
||||
const {
|
||||
AD_TYPE,
|
||||
@@ -586,44 +587,37 @@ class ProstorCrawler {
|
||||
}
|
||||
async loginForScraping(PROSTOR_LOGIN) {
|
||||
console.log("PROSTOR_LOGIN", PROSTOR_LOGIN);
|
||||
let logedin = false;
|
||||
fetch("https://prostor.ba/moj-prostor/prijava", {
|
||||
var formData = new FormData();
|
||||
formData.append("email", PROSTOR_LOGIN.EMAIL);
|
||||
formData.append("password", PROSTOR_LOGIN.PASSWORD);
|
||||
//When once loged in it stays loged in with same credentials.
|
||||
//Do we need to log out ??
|
||||
return fetch("https://prostor.ba/moj-prostor/prijava", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
email: PROSTOR_LOGIN.EMAIL,
|
||||
password: PROSTOR_LOGIN.PASSWORD
|
||||
})
|
||||
body: formData,
|
||||
headers: { Cookie: "ci_session=3a47b6e18b3b9bc146bcde1f95126cbad0f58bf7" }
|
||||
})
|
||||
.then(page => {
|
||||
/* console.log("page", page.text());
|
||||
|
||||
const $ = cheerio.load(page);
|
||||
console.log("$ ", $);
|
||||
if (
|
||||
$(".icons .d-none.d-xl-inline-block.mr-2")
|
||||
.text()
|
||||
.indexOf("Dobrodošli") != -1
|
||||
) {
|
||||
console.log("[PROSTOR]: Crawler loged in!");
|
||||
logedin = true;
|
||||
} else {
|
||||
console.log("[PROSTOR]: Crawler login failed - wrong credentials!");
|
||||
} */
|
||||
|
||||
return page.text();
|
||||
})
|
||||
.then(resp => {
|
||||
// console.log(resp);
|
||||
const $ = cheerio.load(resp);
|
||||
console.log("$ ", $("h1").text());
|
||||
if (
|
||||
$("h1")
|
||||
.text()
|
||||
.indexOf("Dobrodošli") !== -1
|
||||
) {
|
||||
console.log("[PROSTOR]: Crawler loged in!");
|
||||
return true;
|
||||
} else {
|
||||
console.log("[PROSTOR]: Crawler login failed - wrong credentials!");
|
||||
return false;
|
||||
}
|
||||
})
|
||||
|
||||
.catch(err => {
|
||||
console.log("[PROSTOR]: Crawler login error ", err);
|
||||
});
|
||||
//
|
||||
console.log("login in function:", logedin);
|
||||
return logedin;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user