Advertisement
metalx1000

Get UPS Tracking Information with Puppeteer

Sep 9th, 2024
585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/node
  2. const puppeteer = require('puppeteer');
  3. const args = process.argv.slice(2);
  4. const track_num = args[0];
  5.  
  6. (async function main() {
  7.   try {
  8.     const browser = await puppeteer.launch();
  9.     const [page] = await browser.pages();
  10.  
  11.     await page.goto("https://tools.usps.com/go/TrackConfirmAction?qtc_tLabels1=" + track_num, { waitUntil: 'networkidle0' });
  12.     const data = await page.evaluate(() => document.querySelector('.current-tracking-status-wrapper').textContent);
  13. //    let info = data.replaceAll("\t","").replaceAll("\n","");
  14.     let info = data.replaceAll("\t","");
  15.     info = info.replaceAll("\n\n","");
  16.     info = info.split("\n");
  17.     info.reverse();
  18.  
  19.     for(i of info){
  20.       console.log(i);
  21.     }
  22.     await browser.close();
  23.   } catch (err) {
  24.     console.error(err);
  25.   }
  26. })();
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement