Skip to content

Commit

Permalink
fix: selector for Captcha added in selectors list
Browse files Browse the repository at this point in the history
  • Loading branch information
Disane87 committed Oct 31, 2024
1 parent 6e22878 commit d2176c6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 38 deletions.
27 changes: 3 additions & 24 deletions src/commands/scrape/amazon/helpers/auth.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,32 +65,11 @@ export const login = async (
return;
}

const hasCaptcha = !!(await page.$(`form.cvf-widget-form-captcha`));
const hasCaptcha = !!(await page.$(selectors.captchaPage));

if (hasCaptcha) {
const captchaImageUrl = await page.$eval(
selectors.captchaImage,
(image: HTMLImageElement) => image.src,
);
if (captchaImageUrl) {
logger.error(`Auth with captcha is currently unsupported`);

// const captchaImagePage = await browser.newPage();
// const captchaResponse = await captchaImagePage.goto(captchaImageUrl);
// const tempFolder = `./cache/`;
// const imageFilePath = path.join(tempFolder, path.basename(captchaImageUrl.split(`?`)[0]));

// !fs.existsSync(tempFolder) && fs.mkdirSync(tempFolder);
// await fs.writeFileSync(imageFilePath, await captchaResponse.buffer());

// const text = await tessaract.recognize(fs.readFileSync(imageFilePath), {
// lang: `eng`, // default
// debug: true,
// psm: 1
// });
// await captchaImagePage.close();
return false;
}
logger.error(`Captcha detected. Auth with captcha is currently unsupported. Sorry 😣`);
return false
}

// Check if this is the sign in page again i.e. for false password
Expand Down
3 changes: 2 additions & 1 deletion src/commands/scrape/amazon/helpers/selectors.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export const amazonSelectors: AmazonSelectors = {
yearFilter: `select[name='orderFilter']#orderFilter`,
authError: `#auth-error-message-box .a-unordered-list li`,
authWarning: `#auth-warning-message-box .a-unordered-list li`,
captchaImage: `div.cvf-captcha-img img[alt~="captcha"]`,
// captchaImage: `div.cvf-captcha-img img[alt~="captcha"]`,
captchaPage: "form.cvf-widget-form-captcha"
};
27 changes: 14 additions & 13 deletions src/interfaces/selectors.interface.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
export interface AmazonSelectors {
orderCards: string,
invoiceSpans: string,
orderNr: string,
orderDate: string,
popover: string,
invoiceList: string,
invoiceLinks: string,
pagination: string,
yearFilter: string,
authError: string,
authWarning: string,
captchaImage: string
}
orderCards: string,
invoiceSpans: string,
orderNr: string,
orderDate: string,
popover: string,
invoiceList: string,
invoiceLinks: string,
pagination: string,
yearFilter: string,
authError: string,
authWarning: string,
// captchaImage: string
captchaPage: string
}

0 comments on commit d2176c6

Please sign in to comment.