Left substring "token":"
Right substring
","valid_for"Can anybody help me with my code? I'm trying to extract the otp from this html that was pulled. But it's not getting the otp which is 3224 in this case
Html below
[908034738] [18:38:07] Thread #1 : <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <html lang="en"> <head data-id="__react-email-head"> <style> a { text-decoration: none; color: #0975D8; } @media screen and (max-width: 450px) { #tip-box { padding: 40px !important; } } @media screen and (min-width: 450px) { #tip-box { padding: 60px !important; } } </style> </head> <body data-id="__react-email-body" style="font-size:16px;font-family:'Poppins', 'Avenir Next', 'Google Sans', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'Helvetica', 'Roboto', 'Arial', 'Seogoe UI', 'Ubuntu', sans-serif;background-color:rgb(244,247,250);padding:0px;margin:0px"> <table align="center" width="100%" data-id="__react-email-container" role="presentation" cellSpacing="0" cellPadding="0" border="0" style="max-width:37.5em;margin-left:auto;margin-right:auto;box-sizing:border-box;width:450px;table-layout:fixed"> <tbody> <tr style="width:100%"> <td><a href="https://www.sayweee.com" data-id="react-email-link" target="_blank" style="color:#067df7;text-decoration:none;padding-top:1.25rem;padding-bottom:1.25rem;text-align:center;display:block"><img data-id="react-email-img" src="https://img06.weeecdn.com/growth/image/013/780/Weee-v4.png" width="98" height="29" style="display:inline-block;outline:none;border:none;text-decoration:none;width:98px;height:29px" /></a> <table align="center" width="100%" data-id="react-email-section" border="0" cellPadding="0" cellSpacing="0" role="presentation" style="border-width:1px;border-style:solid;border-color:rgb(234,234,234)"> <tbody> <tr> <td> <table align="center" width="100%" data-id="react-email-section" border="0" cellPadding="0" cellSpacing="0" role="presentation" style="background-color:rgb(255,255,255);padding:60px;table-layout:fixed"> <tbody> <tr> <td><img data-id="react-email-img" src="https://img06.weeecdn.com/growth/image/313/008/order-i-check.png" width="80" height="80" style="display:block;outline:none;border:none;text-decoration:none;margin-bottom:1.25rem;margin-left:auto;margin-right:auto" /> <p data-id="react-email-text" style="font-size:48px;line-height:120%;margin:16px 0;font-weight:500;text-align:center;margin-top:0px;margin-bottom:0.625rem;color:rgb(0,158,208)"> 3224 </p> <p data-id="react-email-text" style="font-size:1rem;line-height:120%;margin:16px 0;margin-top:0px;margin-bottom:1.25rem;font-weight:500;color:rgb(119,119,119);text-align:center">Please enter the verification code above to verify your Weee! login.</p> <p data-id="react-email-text" style="font-size:0.75rem;line-height:120%;margin:16px 0;color:rgb(158,158,158);margin-top:0px;margin-bottom:0.625rem;font-weight:500;text-align:center;overflow-wrap:break-word">Thank you for choosing to shop at Weee!</p> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <table align="center" width="100%" data-id="react-email-section" border="0" cellPadding="0" cellSpacing="0" role="presentation" style="padding-left:1.25rem;padding-right:1.25rem;padding-bottom:1.25rem;color:rgb(158,158,158);width:100%;table-layout:fixed"> <tbody> <tr> <td> <table align="center" width="100%" data-id="react-email-row" role="presentation" cellSpacing="0" cellPadding="0" border="0" style="margin:0px"> <tbody style="width:100%"> <tr style="width:100%"> <td align="left" data-id="__react-email-column" style="padding-right:0.625rem;padding-top:1.25rem;width:100%"> <table align="center" width="100%" data-id="react-email-row" role="presentation" cellSpacing="0" cellPadding="0" border="0" style="margin-bottom:1.25rem"> <tbody style="width:100%"> <tr style="width:100%"> <td align="left" data-id="__react-email-column" style="display:inline-block;white-space:nowrap;margin-right:0.625rem"> <p data-id="react-email-text" style="font-size:0.875rem;line-height:120%;margin:0px;display:inline-block;font-weight:500">Download our app</p> </td> <td data-id="__react-email-column" style="width:100%;vertical-align:bottom"> <hr data-id="react-email-hr" style="width:100%;border:none;border-top:1px solid #eaeaea;border-style:none;background-color:rgb(158,158,158);height:1px" /> </td> </tr> </tbody> </table> <table align="center" width="100%" data-id="react-email-row" role="presentation" cellSpacing="0" cellPadding="0" border="0" style="margin-bottom:0.75rem"> <tbody style="width:100%"> <tr style="width:100%"> <td align="left" data-id="__react-email-column"><a href="https://apps.apple.com/app/apple-store/id921864548" data-id="react-email-link" target="_blank" style="color:#067df7;text-decoration:none;padding-bottom:0.5rem;display:inline-block;margin-right:0.625rem"><img data-id="react-email-img" src="https://img06.weeecdn.com/growth/image/172/805/app-store-new.png" width="118" height="36" style="display:block;outline:none;border:none;text-decoration:none" /></a><a href="https://play.google.com/store/apps/details?id=com.sayweee.weee" data-id="react-email-link" target="_blank" style="color:#067df7;text-decoration:none;padding-bottom:0.5rem;display:inline-block"><img data-id="react-email-img" src="https://img06.weeecdn.com/growth/image/187/551/google-play-new.png" width="125" height="36" style="display:block;outline:none;border:none;text-decoration:none" /></a></td> </tr> </tbody> </table> </td> <td align="right" data-id="__react-email-column"><img data-id="react-email-img" src="https://img06.weeecdn.com/growth/image/990/357/QR-Code.png" width="73" height="73" style="display:block;outline:none;border:none;text-decoration:none" /></td> </tr> </tbody> </table> <table align="center" width="100%" data-id="react-email-row" role="presentation" cellSpacing="0" cellPadding="0" border="0" style="padding-top:0.625rem;padding-bottom:0.625rem;margin:0px"> <tbody style="width:100%"> <tr style="width:100%"> <td align="left" data-id="__react-email-column"><a href="https://www.sayweee.com" data-id="react-email-link" target="_blank" style="color:#067df7;text-decoration:none"><img data-id="react-email-img" src="https://img06.weeecdn.com/growth/image/013/780/Weee-v4.png" width="81" height="24" style="display:block;outline:none;border:none;text-decoration:none" /></a></td> <td align="right" data-id="__react-email-column"><a href="https://www.facebook.com/sayweee/?ref=aymt_homepage_panel" data-id="react-email-link" target="_blank" style="color:#067df7;text-decoration:none"><img data-id="react-email-img" alt="" src="https://img06.weeecdn.com/growth/image/229/310/media1.png" width="20" height="20" style="display:inline-block;outline:none;border:none;text-decoration:none;margin-right:1.25rem" /></a><a href="https://www.instagram.com/sayweee_official" data-id="react-email-link" target="_blank" style="color:#067df7;text-decoration:none"><img data-id="react-email-img" alt="" src="https://img06.weeecdn.com/growth/image/472/451/media2.png" width="20" height="20" style="display:inline-block;outline:none;border:none;text-decoration:none;margin-right:1.25rem" /></a><a href="https://www.linkedin.com/company/weee-/" data-id="react-email-link" target="_blank" style="color:#067df7;text-decoration:none"><img data-id="react-email-img" alt="" src="https://img06.weeecdn.com/growth/image/453/917/media3.png" width="20" height="20" style="display:inline-block;outline:none;border:none;text-decoration:none;margin-right:1.25rem" /></a><a href="https://www.youtube.com/channel/UCmtycD943w_ZI2illCA9tvA" data-id="react-email-link" target="_blank" style="color:#067df7;text-decoration:none"><img data-id="react-email-img" alt="" src="https://img06.weeecdn.com/growth/image/054/313/media4.png" width="20" height="20" style="display:inline-block;outline:none;border:none;text-decoration:none;margin-right:1.25rem" /></a><a href="https://twitter.com/weee_official/" data-id="react-email-link" target="_blank" style="color:#067df7;text-decoration:none"><img data-id="react-email-img" alt="" src="https://img06.weeecdn.com/growth/image/993/057/media5.png" width="20" height="20" style="display:inline-block;outline:none;border:none;text-decoration:none" /></a></td> </tr> </tbody> </table> <table align="center" width="100%" data-id="react-email-row" role="presentation" cellSpacing="0" cellPadding="0" border="0" style="margin:0px"> <tbody style="width:100%"> <tr style="width:100%"> <table align="center" width="100%" data-id="react-email-section" border="0" cellPadding="0" cellSpacing="0" role="presentation" style="text-align:center;font-weight:700;padding-top:1.25rem;padding-bottom:0.625rem;font-size:0.75rem;line-height:1rem"> <tbody> <tr> <td><a href="https://www.sayweee.com/zh/home/privacy_and_security" data-id="react-email-link" target="_blank" style="color:#067df7;text-decoration:none"> <p data-id="react-email-text" style="font-size:0.75rem;line-height:142%;margin:16px 0;color:rgb(158,158,158) !important;display:inline;margin-right:1rem">Privacy policy</p> </a><a href="https://www.sayweee.com/zh/home/terms_of_service" data-id="react-email-link" target="_blank" style="color:#067df7;text-decoration:none"> <p data-id="react-email-text" style="font-size:0.75rem;line-height:142%;margin:16px 0;color:rgb(158,158,158) !important;display:inline;margin-right:1rem">Terms of service</p> </a><a href="https://www.sayweee.com/en/me/setting_notification" data-id="react-email-link" target="_blank" style="color:#067df7;text-decoration:none"> <p data-id="react-email-text" style="font-size:0.75rem;line-height:142%;margin:16px 0;color:rgb(158,158,158) !important;display:inline">Unsubscribe</p> </a></td> </tr> </tbody> </table> <table align="center" width="100%" data-id="react-email-section" border="0" cellPadding="0" cellSpacing="0" role="presentation" style="text-align:center;font-size:0.75rem;line-height:1rem;padding-bottom:0.625rem;color:rgb(158,158,158) !important"> <tbody> <tr> <td> <p data-id="react-email-text" style="font-size:0.75rem;line-height:142%;margin:16px 0;display:inline">47467 Fremont Blvd</p> <p data-id="react-email-text" style="font-size:14px;line-height:24px;margin:16px 0;display:inline;margin-left:0.25rem;margin-right:0.25rem">·</p> <p data-id="react-email-text" style="font-size:0.75rem;line-height:142%;margin:16px 0;display:inline">Fremont, CA 94538</p> <p data-id="react-email-text" style="font-size:14px;line-height:24px;margin:16px 0;display:inline;margin-left:0.25rem;margin-right:0.25rem">·</p> <p data-id="react-email-text" style="font-size:0.75rem;line-height:142%;margin:16px 0;display:inline">© 2023 Weee!, Inc.</p> </td> </tr> </tbody> </table> <p data-id="react-email-text" style="font-size:0.75rem;line-height:142%;margin:0px;padding-bottom:0.625rem;text-align:center">You received this email because you signed up for an account or changed your email information. Please disregard and delete this email if you did not sign up.</p> <p data-id="react-email-text" style="font-size:0.75rem;line-height:142%;margin:0px;text-align:center">Do not share this email with anyone. Weee! value the security of your account very much. Weee! Customer service will never ask you to disclose or verify your password, verification code, credit card, or bank account. If you receive a suspicious email with a link to update your account information, please do not click on the link and instead report the email to Weee for investigation.</p> </tr> </tbody> </table> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <img width="1" height="1" alt="" src="https://email-tracking.sayweee.com/o/eJx8jEFuwyAQAF8TbkSwhgUOvMVaw-KiNCECbKu_r9IH9DqjmRw1MmorOGq3hAWcd1Z8RSQEpXzGAhwUkrcpbIv3OfiCHrOoERRYBRoULM7aO26YNSTtqBAVsjejBv1czHxP7Sl6NF6PxwsuuG5Gvds8Mt9b38VoR08sU8scOa3pGLM9uYsZP7F88hi0sxzcz5pYvnsWMx6D-1pa33mubxrjan_4u-31tZ7ca6mJZm2v9fNdTy0m7f_qTukha47kt7wZhdKjJWkMsdyCCdJmlxw7U3QgcUb4DQAA__8JEma8"></body> </html>
Code below for extracting
const fs = require('fs');
const { simpleParser } = require('mailparser');
try {
// Parse the email
const parsedEmail = await simpleParser([[EMAIL_CONTENT]]);
// Combine text and HTML content for searching
const content = (parsedEmail.text || '') + (parsedEmail.html || '');
// Use a regular expression to find the number
const numberMatch = content.match(/<p[^>]*style=["'][^"']*["'][^>]*>(\d+)<\/p>/);
if (numberMatch) {
const extractedNumber = numberMatch[1];
//console.log(extractedNumber);
//console.log('Extracted Number:' + extractedNumber);
[[EMAIL_OTP]] = numberMatch[1];
} else {
//console.log(numberMatch);
console.log('Number not found in the email content.');
}
} catch (parseError) {
console.error('Error parsing email:', parseError);
}