WIP Changed login to crawler.
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
const fetch = require("node-fetch");
|
const fetch = require("node-fetch");
|
||||||
const cheerio = require("cheerio");
|
const cheerio = require("cheerio");
|
||||||
const moment = require("moment-timezone");
|
const moment = require("moment-timezone");
|
||||||
|
const FormData = require("form-data");
|
||||||
|
|
||||||
const {
|
const {
|
||||||
AD_TYPE,
|
AD_TYPE,
|
||||||
@@ -586,44 +587,37 @@ class ProstorCrawler {
|
|||||||
}
|
}
|
||||||
async loginForScraping(PROSTOR_LOGIN) {
|
async loginForScraping(PROSTOR_LOGIN) {
|
||||||
console.log("PROSTOR_LOGIN", PROSTOR_LOGIN);
|
console.log("PROSTOR_LOGIN", PROSTOR_LOGIN);
|
||||||
let logedin = false;
|
var formData = new FormData();
|
||||||
fetch("https://prostor.ba/moj-prostor/prijava", {
|
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",
|
method: "POST",
|
||||||
body: JSON.stringify({
|
body: formData,
|
||||||
email: PROSTOR_LOGIN.EMAIL,
|
headers: { Cookie: "ci_session=3a47b6e18b3b9bc146bcde1f95126cbad0f58bf7" }
|
||||||
password: PROSTOR_LOGIN.PASSWORD
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.then(page => {
|
.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();
|
return page.text();
|
||||||
})
|
})
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
// console.log(resp);
|
|
||||||
const $ = cheerio.load(resp);
|
const $ = cheerio.load(resp);
|
||||||
console.log("$ ", $("h1").text());
|
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 => {
|
.catch(err => {
|
||||||
console.log("[PROSTOR]: Crawler login error ", err);
|
console.log("[PROSTOR]: Crawler login error ", err);
|
||||||
});
|
});
|
||||||
//
|
|
||||||
console.log("login in function:", logedin);
|
|
||||||
return logedin;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
30
package-lock.json
generated
30
package-lock.json
generated
@@ -1346,13 +1346,23 @@
|
|||||||
"integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE="
|
"integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE="
|
||||||
},
|
},
|
||||||
"form-data": {
|
"form-data": {
|
||||||
"version": "2.3.3",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz",
|
"resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.0.tgz",
|
||||||
"integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==",
|
"integrity": "sha512-CKMFDglpbMi6PyN+brwB9Q/GOw0eAnsrEZDgcsH5Krhz5Od/haKHAX0NmQfha2zPPz0JpWzA7GJHGSnvCRLWsg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"asynckit": "^0.4.0",
|
"asynckit": "^0.4.0",
|
||||||
"combined-stream": "^1.0.6",
|
"combined-stream": "^1.0.8",
|
||||||
"mime-types": "^2.1.12"
|
"mime-types": "^2.1.12"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"combined-stream": {
|
||||||
|
"version": "1.0.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||||
|
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
||||||
|
"requires": {
|
||||||
|
"delayed-stream": "~1.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"forwarded": {
|
"forwarded": {
|
||||||
@@ -3430,6 +3440,18 @@
|
|||||||
"tough-cookie": "~2.4.3",
|
"tough-cookie": "~2.4.3",
|
||||||
"tunnel-agent": "^0.6.0",
|
"tunnel-agent": "^0.6.0",
|
||||||
"uuid": "^3.3.2"
|
"uuid": "^3.3.2"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"form-data": {
|
||||||
|
"version": "2.3.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz",
|
||||||
|
"integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==",
|
||||||
|
"requires": {
|
||||||
|
"asynckit": "^0.4.0",
|
||||||
|
"combined-stream": "^1.0.6",
|
||||||
|
"mime-types": "^2.1.12"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"require-directory": {
|
"require-directory": {
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
"express": "^4.16.4",
|
"express": "^4.16.4",
|
||||||
"express-ejs-layouts": "^2.5.0",
|
"express-ejs-layouts": "^2.5.0",
|
||||||
"express-layout": "^0.1.0",
|
"express-layout": "^0.1.0",
|
||||||
|
"form-data": "^3.0.0",
|
||||||
"html-to-text": "^5.1.1",
|
"html-to-text": "^5.1.1",
|
||||||
"moment": "^2.24.0",
|
"moment": "^2.24.0",
|
||||||
"moment-timezone": "^0.5.26",
|
"moment-timezone": "^0.5.26",
|
||||||
|
|||||||
Reference in New Issue
Block a user