const puppeteer = require('puppeteer');
const diameter = "84"; // tank diameter
const length = "167"; // tank length
const volumeMap = new Map();
function sleep (time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
const gallons = [
//Input gallon number here
];
(async () => {
const browser = await puppeteer.launch({
headless: false,
args: ['--headless'],
})
const page = await browser.newPage();
for (var gallon of gallons) {
const navigationPromise = page.waitForNavigation({ waitUntil: ['networkidle2'] });
await page.goto('https://www.handymath.com/cgi-bin/circlehei4.cgi?convdia=in&convlen=in&convol=gal&convhei=in&dia1=&len1=&vol1=&dia2=&len2=&vol2=&numnum=2&submit=Remove+Rows&moreless=1&decimal=5',
{ waitUntil: "domcontentloaded" });
const diameterBox = await page.$x("//input[@name='dia1']");
await diameterBox[0].click();
await diameterBox[0].type(diameter);
const lengthBox = await page.$x("//input[@name='len1']");
await lengthBox[0].click();
await lengthBox[0].type(length);
const liquidBox = await page.$x("//input[@name='vol1']");
await liquidBox[0].click();
await liquidBox[0].type(gallon.toString());
var calculateBtn = await page.$x("//input[@value='Calculate']");
await calculateBtn[0].click();
await navigationPromise
//await page.screenshot({ path: 'example.png' });
const inches = await page.$$eval("body > table > tbody > tr > td:nth-child(2) > table:nth-child(10) > tbody > tr:nth-child(3) > td:nth-child(4)", ele => ele[0].textContent);
console.log(inches);
}
await browser.close();
})();