const fs = require("fs").promises; // const puppeteer = require('puppeteer-extra'); // const StealthPlugin = require('puppeteer-extra-plugin-stealth') // const cheerio = require("cheerio"); // const devices = require('../DeviceDescriptors'); // const iPhonex = devices['iPhone X']; const selectors = { price1: 'span.a-price.a-text-price.a-size-medium.apexPriceToPay > span:nth-child(2)', price2: 'span.a-price.aok-align-center.priceToPay > span.a-offscreen', coupon: '#promoPriceBlockMessage_feature_div > span > div > label' } // puppeteer.use(StealthPlugin()) const puppeteer = require('puppeteer-extra') // Enable stealth plugin with all evasions puppeteer.use(require('puppeteer-extra-plugin-stealth')()) async function amazonBuyer(tgUrl) { // Launch the browser in headless mode and set up a page. const browser = await puppeteer.launch({ args: ['--no-sandbox'], headless: true }) page = await browser.newPage(); await page.setExtraHTTPHeaders({ 'Accept-Language': 'en-GB,en-US;q=0.9,en;q=0.8', "User-Agent": "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36" }); const cookiesString = await fs.readFile("./cookies.json"); const cookies = JSON.parse(cookiesString); await page.setCookie(...cookies); await page.goto(tgUrl, { waitUntil: 'domcontentloaded' }); await page.waitForSelector('#buy-now-button', { visible: true, hidden: false, }) await page.click('#buy-now-button', { waitUntil: 'domcontentloaded' }); console.log(`buy click`); console.log('trying to use address') await page.click('#orderSummaryPrimaryActionBtn > span > input', { visible: true, hidden: false, }); console.log(`use this adress done`); await page.waitForTimeout(3000); await page.click(".a-js .a-native-dropdown, .a-js .a-native-splitdropdown"); console.log(`NETBANING ICON`); await page.waitForTimeout(2000); await page.evaluate(() => { const elements = [...document.querySelectorAll('a')]; const targetElement = elements.find(e => e.innerText == 'ICICI Bank'); if (targetElement) targetElement.click(); }); await page.waitForTimeout(1000); await page.evaluate(() => { const elements = [...document.querySelectorAll('span')]; const targetElement = elements.find(e => e.innerText == 'Use this payment method'); if (targetElement) targetElement.click(); }); console.log(`confirming your order`); await page.waitForTimeout(9000); await page.evaluate(() => { Array.from(document.querySelectorAll('span')).filter(span => { return span.innerText == 'Place Your Order and Pay' // filter il for specific text }).forEach(element => { if (element) element.click(); // click on span with specific text }); }); await page.waitForTimeout(6000); console.log(`Your Order has Been Sucessfully Placed`); await page.screenshot({ path: 'order.png', fullPage: true }); await page.waitForTimeout(1000) await page.close(); await browser.close(); }; module.exports = { amazonBuyer };
Write, Run & Share NodeJS code online using OneCompiler's NodeJS online compiler for free. It's one of the robust, feature-rich online compilers for NodeJS language,running on the latest LTS version NodeJS 16.14.2. Getting started with the OneCompiler's NodeJS editor is easy and fast. The editor shows sample boilerplate code when you choose language as NodeJS and start coding. You can provide the dependencies in package.json
.
Node.js is a free and open-source server environment. Node.js is very popular in recent times and a large number of companies like Microsoft, Paypal, Uber, Yahoo, General Electric and many others are using Node.js.
Google chrome's javascript engine V8
and is pretty fast.Asynchronous
, event-driven
and works on single-thread model
thus eliminating the dis-advantages of multi-thread model.Express is one of the most popular web application framework in the NodeJS echosystem.
let moment = require('moment');
console.log(moment().format('MMMM Do YYYY, h:mm:ss a'));
const _ = require("lodash");
let colors = ['blue', 'green', 'yellow', 'red'];
let firstElement = _.first(colors);
let lastElement = _.last(colors);
console.log(`First element: ${firstElement}`);
console.log(`Last element: ${lastElement}`);
Following are the libraries supported by OneCompiler's NodeJS compiler.