2

So I'm trying to test a recaptcha implementation by writing my own spambot using React and Puppeteer. I got the script ready to do a single form submission after executing the script, but what I'm actually hoping for is to have my script loop through a database with form submission details, and then reiterate every row of the csv file until it's depleted the database.

So far I have the following script:

const puppeteer = require('puppeteer');

// Server Authentication
const username = "username";
const password = 'password';

(async () => {
  const browser = await puppeteer.launch();

  const page = await browser.newPage();

  // Pass server side authentication needed for website when accessing url
  await page.authenticate({ username, password});


  // Load page with form and take screenshot to confirm page has been reached
  await page.goto('https://pagewiththeformimtryingtosubmit.com');
  await page.screenshot({path: 'example2.png'});


  // Click away cookie pop-up banner, take screenshot after
  page.keyboard.press('Escape');
  await page.screenshot({path: 'cookiebotcleared.png', fullPage: true});

  // Fill in first form fields, screenshot to see if it works
  await page.type('#firstname', 'Somename', {delay:500});
  await page.type('#lastname', 'Somelastname', {delay:500});
  await page.type('#telephone', '123456789', {delay:500});
  await page.type('#email_address', 'somename.lastname@gmail.com', {delay:500});
  await page.type('#password', 'Chooseapassword', {delay:500});
  await page.type('#password-confirmation', 'Chooseapassword', {delay:500});
  await page.click('.consent', {delay:500});
  await page.click('.submit', {delay: 500});
  // Take screenshot after form submission to see if it has worked
  await page.screenshot({path: 'formfillout.png', fullPage: true}, {delay: 500});

  await browser.close();
})();

What I'm trying to do, is take a CSV with all the data I've randomized, and then have this script run but take elements from the csv for the various form inputs and loop that over.

I've tried working with CSVToJSON in order to process the csv database into objects that I should then be able to use in my code:

const CSVToJSON = require('csvtojson')

CSVToJSON().fromFile('formbot_database.csv')
    .then(users => {
        console.log(users);
        console.log(users.firstname);
    }).catch(err => {
        console.log(err);
    });

Here's where my first troubles start: I want to take the row headers of my database to map them to variables, so I can process those variables within my script. I first tried users.firstname, but when I console log that, it gives me undefined.

If anyone has any suggestion on how I can work this through, that'd be great. I've tried visiting multiple resources but can't figure it out I'm afraid.

Thanks in advance!

  • Please `await page.keyboard.press('Escape');`. Beyond that, it's pretty much impossible to help without seeing a [mcve] of the CSV file, the expected result and the page you're manipulating. Or, if the only problem is the CSV code, you may omit all of the Puppeteer stuff and focus on that sub-problem exclusively. Thanks. – ggorlen Oct 03 '22 at 17:13

0 Answers0