try to use speechtext server
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
const axios = require("axios");
|
||||
const PLAY_AUDIO_BTN_ID = ".audio-captcha-play-button"
|
||||
const wget = require('node-wget');
|
||||
const crypto = require('crypto');
|
||||
const fs = require("fs");
|
||||
const homedir = require('os').homedir();
|
||||
const dest_dir = homedir + "/wavs/"
|
||||
// iframe.query_selector('.audio-captcha-track').inner_html()
|
||||
@@ -17,6 +19,32 @@ function delay(delayInMs) {
|
||||
});
|
||||
}
|
||||
|
||||
function getRandom() {
|
||||
return Math.floor(Math.random() * 3);
|
||||
}
|
||||
|
||||
function getRandomWaitTime() {
|
||||
return getRandom() * 1000
|
||||
}
|
||||
|
||||
|
||||
async function sendRequest(fileName, callback) {
|
||||
const fileStream = fs.createReadStream(fileName);
|
||||
let response = await axios.post('http://127.0.0.1:8000', fileStream, {
|
||||
headers: {
|
||||
'Content-Type': 'wav'
|
||||
}
|
||||
})
|
||||
if (response.status === 200) {
|
||||
let result = response.data;
|
||||
console.log(result);
|
||||
callback(result)
|
||||
} else {
|
||||
console.log("error")
|
||||
callback([])
|
||||
}
|
||||
}
|
||||
|
||||
class GeoCaptchaSolver {
|
||||
constructor(page) {
|
||||
this.page = page
|
||||
@@ -29,36 +57,49 @@ class GeoCaptchaSolver {
|
||||
let iframeHandler = await this.page.frameLocator("body > iframe");
|
||||
let playAudioBtn = await iframeHandler.locator(PLAY_AUDIO_BTN_ID);
|
||||
playAudioBtn.click();
|
||||
await delay(5000);
|
||||
// let captcha_track = await iframeHandler.locator(AUDIO_CAPTCHA_TRACK);
|
||||
// const handle = await this.page.frameLocator("iframe");
|
||||
// const contentFrame = await handle.contentFrame();
|
||||
// console.log(contentFrame)
|
||||
await delay(5000 + getRandomWaitTime());
|
||||
let captcha_container = await iframeHandler.locator(CAPTCHA_CONTAINER)
|
||||
// let result = await iframeHandler.evaluate(() => {
|
||||
// document.getElementsByClassName(AUDIO_CAPTCHA_TRACK)
|
||||
// })
|
||||
let html = await captcha_container.innerHTML()
|
||||
console.log("audio_tag: " + html);
|
||||
// find wav from html
|
||||
this.findWavFile(html)
|
||||
await this.findTextFromWavFile(html, (number_list) => {
|
||||
for (i; i < number_list.length; i++) {
|
||||
this.page.evaluate((info) => {
|
||||
let input_fileds = document.getElementsByClassName("audio-captcha-inputs");
|
||||
input_fileds[info.index].focus();
|
||||
input_fileds[info.index].value = info.number;
|
||||
}, {'index': i, 'number': number_list[i]})
|
||||
delay(getRandomWaitTime());
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
findWavFile(html) {
|
||||
async findTextFromWavFile(html) {
|
||||
let result = re.exec(html);
|
||||
//create the directory if not exist
|
||||
await fs.promises.mkdir(dest_dir, {recursive: true});
|
||||
if (result) {
|
||||
let audioUrl = result[0]
|
||||
let fileName = crypto.randomUUID() + ".wav"
|
||||
let audioUrl = result[0];
|
||||
let fileName = crypto.randomUUID() + ".wav";
|
||||
wget({url: audioUrl, dest: dest_dir + fileName}, function (error, response, body) {
|
||||
if (error) {
|
||||
console.log('--- error:');
|
||||
console.log(error); // error encountered
|
||||
} else {
|
||||
console.log('download the file successfully');
|
||||
// send request to get numbers
|
||||
sendRequest(fileName);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
module.exports = GeoCaptchaSolver
|
||||
module.exports = GeoCaptchaSolver
|
||||
|
||||
// sendRequest("/Users/lpan/wavs/42f90d53-17c0-4a9b-a585-59eaa737a80d.wav").then(r => {
|
||||
// console.log(r)
|
||||
// })
|
||||
Reference in New Issue
Block a user