Как получить код проверки, здесь я пытаюсь выполнить следующее регулярное выражение с помощью обрезки, но появляется сообщение об ошибке «Ошибка типа: не удается прочитать свойства неопределенного (чтение« обрезки »)»
И я просто хочу получить код подтверждения, как на картинке
my code
const checkInboxUrl = 'https://getnada.com/api/v1/inboxes/';
const getMessageUrl = 'https://getnada.com/api/v1/messages/html/';
const refreshMailboxUrl = 'https://getnada.com/api/v1/u/';
/* eslint-disable no-unused-vars */
class Getnada {
constructor() {
this.email = '';
this.verificationCode = '';
}
async getEmail(email = 'urmxhbwrz@getnada.com') {
this.email = email;
return this;
}
async getMailbox(pattern, sleepTime = 5000) {
await sleep(sleepTime);
const timestamp = Math.floor(new Date().getTime() / 1000);
const refreshMailboxResponse = await fetch(refreshMailboxUrl + this.email + '/' + timestamp);
const checkInboxResponse = await fetch(checkInboxUrl + this.email);
const checkInboxJson = await checkInboxResponse.json();
const getMessageResponse = await fetch(getMessageUrl + checkInboxJson.msgs[0].uid);
const readInbox = await getMessageResponse.text();
const regex = new RegExp(pattern);
const verificationCodeMatch = regex.exec(readInbox);
this.verificationCode = verificationCodeMatch[1].trim();
console.info(verificationCodeMatch)
return this;
}
}
const getnada = new Getnada();
async function main() {
console.info((await getnada.getEmail()))
console.info((await getnada.getMailbox()))
}
main();
Https://getnada.com/api/v1/messages/html/8lra5CwOQcHvja3mpQZgO7G5RPTS3W
Извините, я не знаю, как @Fcmam5
Вы должны добавить что-то к своему вызову функции: console.info((await getnada.getMailbox(SOMETHING))) И это SOMETHING то, что вы хотите проанализировать со страницы.
Чтобы получить код подтверждения, вы можете попробовать изменить эти строки:
const regex = new RegExp(pattern);
const verificationCodeMatch = regex.exec(readInbox);
this.verificationCode = verificationCodeMatch[1].trim();
К :
const verificationCodeMatch = pattern.exec(readInbox);
this.verificationCode = verificationCodeMatch[0].trim();
И также измените эту строку:
console.info((await getnada.getMailbox()))
К :
console.info((await getnada.getMailbox(/\b\d{6,6}\b/)));
Это регулярное выражение /\b\d{6,6}\b/ будет отфильтровывать строки, содержащие ровно 6 цифр чисел, которые являются проверочным кодом.
Вы не передаете шаблон для вызова getMailbox