use ocr to identifier page content
This commit is contained in:
+2
-1
@@ -20,7 +20,8 @@
|
|||||||
"node-wget": "^0.4.3",
|
"node-wget": "^0.4.3",
|
||||||
"node-xlsx": "^0.21.0",
|
"node-xlsx": "^0.21.0",
|
||||||
"playwright": "^1.32.1",
|
"playwright": "^1.32.1",
|
||||||
"puppeteer": "^1.20.0",
|
"puppeteer": "^15.5.0",
|
||||||
|
"node-tesseract-ocr": "^2.2.1",
|
||||||
"ws": "^6.2.0",
|
"ws": "^6.2.0",
|
||||||
"read-ini-file": "^3.0.1",
|
"read-ini-file": "^3.0.1",
|
||||||
"uuid": "^9.0.0",
|
"uuid": "^9.0.0",
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ const {
|
|||||||
const GeoCaptchaSolver = require("./GeoCaptchaSolver");
|
const GeoCaptchaSolver = require("./GeoCaptchaSolver");
|
||||||
const SlidingCaptchaSolver = require("./SlidingCaptchaSolver");
|
const SlidingCaptchaSolver = require("./SlidingCaptchaSolver");
|
||||||
const {de} = require("yarn/lib/cli");
|
const {de} = require("yarn/lib/cli");
|
||||||
|
const OCRChecker = require("./OCRChecker");
|
||||||
// const RDV_URL = "http://192.168.0.44:8000/test_appointment.html"
|
// const RDV_URL = "http://192.168.0.44:8000/test_appointment.html"
|
||||||
const RDV_URL = "https://rendezvousparis.hermes.com/client/register";
|
const RDV_URL = "https://rendezvousparis.hermes.com/client/register";
|
||||||
const BLANK_URL = "about:blank"
|
const BLANK_URL = "about:blank"
|
||||||
@@ -321,8 +322,8 @@ class CommandorPage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async clickValid(page) {
|
async clickValid() {
|
||||||
await this.saveCookies()
|
// await this.saveCookies()
|
||||||
await delay(getRandomWaitTime())
|
await delay(getRandomWaitTime())
|
||||||
try {
|
try {
|
||||||
if (!this.page.isClosed()) {
|
if (!this.page.isClosed()) {
|
||||||
@@ -337,9 +338,15 @@ class CommandorPage {
|
|||||||
// remove debug flag
|
// remove debug flag
|
||||||
// const validElement = await page.$('.btn');
|
// const validElement = await page.$('.btn');
|
||||||
console.log("will click on valid button")
|
console.log("will click on valid button")
|
||||||
|
console.log("will click on valid button")
|
||||||
|
console.log("will click on valid button")
|
||||||
this.page.evaluate(() => {
|
this.page.evaluate(() => {
|
||||||
document.getElementsByClassName("btn")[0].click();
|
document.getElementsByClassName("btn")[0].click();
|
||||||
})
|
})
|
||||||
|
// this.browser.disconnect();
|
||||||
|
await delay(2000);
|
||||||
|
let ocrChecker = new OCRChecker(this.device, this.contact)
|
||||||
|
await ocrChecker.get_result()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log(e)
|
log(e)
|
||||||
}
|
}
|
||||||
@@ -360,6 +367,7 @@ class CommandorPage {
|
|||||||
let pageContent = await page.content()
|
let pageContent = await page.content()
|
||||||
let hasCaptcha = pageContent.includes("g-recaptcha-response")
|
let hasCaptcha = pageContent.includes("g-recaptcha-response")
|
||||||
if (hasCaptcha) {
|
if (hasCaptcha) {
|
||||||
|
// await this.browser.disconnect()
|
||||||
await this.clickCheckbox()
|
await this.clickCheckbox()
|
||||||
await delay(1000)
|
await delay(1000)
|
||||||
this.captchaSolver = new SolveCaptcha(page);
|
this.captchaSolver = new SolveCaptcha(page);
|
||||||
@@ -511,7 +519,7 @@ class CommandorPage {
|
|||||||
} else {
|
} else {
|
||||||
log("audioBtn not found")
|
log("audioBtn not found")
|
||||||
console.log("audioBtn not found")
|
console.log("audioBtn not found")
|
||||||
console.log("we are blocked")
|
logWithDevice("we are blocked", this.device)
|
||||||
await this.resetBrowser()
|
await this.resetBrowser()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -533,7 +541,7 @@ class CommandorPage {
|
|||||||
// log("onResponse with url:" + response.url())
|
// log("onResponse with url:" + response.url())
|
||||||
// log("onResponse with url:" + response.body())
|
// log("onResponse with url:" + response.body())
|
||||||
if (rex.test(response.url())) {
|
if (rex.test(response.url())) {
|
||||||
log("rdv url found:" + response.url())
|
logWithDevice("rdv url found:" + response.url(), this.device)
|
||||||
// save cookies
|
// save cookies
|
||||||
await this.saveCookies();
|
await this.saveCookies();
|
||||||
await this.push_message_to_db(PublishType.SUCCESS, response.url())
|
await this.push_message_to_db(PublishType.SUCCESS, response.url())
|
||||||
@@ -591,12 +599,26 @@ class CommandorPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async clickCheckbox() {
|
async clickCheckbox() {
|
||||||
// try {
|
try {
|
||||||
// // let errorItem = await this.page.click("#recaptcha-anchor > div.recaptcha-checkbox-border")
|
// let errorItem = await this.page.click("#recaptcha-anchor > div.recaptcha-checkbox-border")
|
||||||
// await this.page.$('[title="reCAPTCHA"]').getByRole('checkbox', {name: 'I\'m not a robot'}).click();
|
await this.page.waitForSelector("iframe")
|
||||||
// } catch (e) {
|
let elementHandle = await this.page.$('[title="reCAPTCHA"]')
|
||||||
// log(e);
|
const iframe = await elementHandle.contentFrame()
|
||||||
|
await iframe.click("#recaptcha-anchor > div.recaptcha-checkbox-border")
|
||||||
|
// // .getByRole('checkbox', {name: 'I\'m not a robot'})
|
||||||
|
// if (enCheckbox) {
|
||||||
|
// enCheckbox.click()
|
||||||
|
// } else {
|
||||||
|
// let frCheckbox = await this.page.$('[title="reCAPTCHA"]').getByRole('checkbox', {name: 'Je ne suis pas un robot'})
|
||||||
|
// if (frCheckbox) {
|
||||||
|
// frCheckbox.click()
|
||||||
|
// } else {
|
||||||
|
// console.log("recaptcha checkbox not found")
|
||||||
// }
|
// }
|
||||||
|
// }
|
||||||
|
} catch (e) {
|
||||||
|
log(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleError(errorContent) {
|
async handleError(errorContent) {
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
const {v4: uuidv4} = require("uuid");
|
||||||
|
const tesseract = require("node-tesseract-ocr");
|
||||||
|
|
||||||
|
function delay(delayInMs) {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
setTimeout(() => {
|
||||||
|
resolve(2);
|
||||||
|
}, delayInMs);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const config = {
|
||||||
|
lang: "eng",
|
||||||
|
oem: 1,
|
||||||
|
psm: 3,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class OCRChecker {
|
||||||
|
|
||||||
|
constructor(device, contact) {
|
||||||
|
this.device = device;
|
||||||
|
this.contact = contact;
|
||||||
|
}
|
||||||
|
|
||||||
|
get_file_name() {
|
||||||
|
let uuid = uuidv4();
|
||||||
|
return this.contact.passportNumber + "_" + uuid + ".png"
|
||||||
|
}
|
||||||
|
|
||||||
|
async get_result() {
|
||||||
|
let fileName = await this.take_screen_shot()
|
||||||
|
let result = await tesseract
|
||||||
|
.recognize(fileName, config)
|
||||||
|
console.log(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
async take_screen_shot() {
|
||||||
|
let name = this.get_file_name()
|
||||||
|
await this.device.screenshot({path: name});
|
||||||
|
await delay(1000);
|
||||||
|
return name
|
||||||
|
// console.log(`stdout: ${stdout1}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
module.exports = OCRChecker
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const {exec} = require("child_process");
|
const {exec} = require("child_process");
|
||||||
|
|
||||||
const Position = require("../models/Position");
|
|
||||||
|
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
const {v4: uuidv4} = require('uuid');
|
const {v4: uuidv4} = require('uuid');
|
||||||
|
|
||||||
@@ -20,12 +18,6 @@ function randomIntFromInterval(min, max) { // min and max included
|
|||||||
return Math.floor(Math.random() * (max - min + 1) + min)
|
return Math.floor(Math.random() * (max - min + 1) + min)
|
||||||
}
|
}
|
||||||
|
|
||||||
const positionInfo = new Map();
|
|
||||||
|
|
||||||
positionInfo.set("2109119DG", new Position(211, 1710))
|
|
||||||
positionInfo.set("ONEPLUS A6000", new Position(211, 1706))
|
|
||||||
positionInfo.set("SM-C5000", new Position(180, 1794))
|
|
||||||
|
|
||||||
class SlidingCaptchaSolver {
|
class SlidingCaptchaSolver {
|
||||||
constructor(device) {
|
constructor(device) {
|
||||||
this.device = device;
|
this.device = device;
|
||||||
@@ -54,7 +46,7 @@ class SlidingCaptchaSolver {
|
|||||||
//get resolution of screen
|
//get resolution of screen
|
||||||
await this.sendRequest(blockedImageFileName, async (detectedPositionList) => {
|
await this.sendRequest(blockedImageFileName, async (detectedPositionList) => {
|
||||||
console.log("detectedPosition is " + detectedPositionList);
|
console.log("detectedPosition is " + detectedPositionList);
|
||||||
if (detectedPositionList.length === 2) {
|
if (detectedPositionList.length >= 2) {
|
||||||
// #xiaomi
|
// #xiaomi
|
||||||
let startPosition = detectedPositionList.filter((positionInfo) => {
|
let startPosition = detectedPositionList.filter((positionInfo) => {
|
||||||
return positionInfo.label === "origin"
|
return positionInfo.label === "origin"
|
||||||
|
|||||||
Reference in New Issue
Block a user