Advertisement
dereksir

Untitled

Dec 26th, 2023
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const puppeteer = require('puppeteer');
  2.  
  3. (async () => {
  4.   // launch a headless browser
  5.   const browser = await puppeteer.launch();
  6.  
  7.   // open a new page
  8.   const page = await browser.newPage();
  9.  
  10.   // set a custom user agent (replace it with your desired user agent)
  11.   await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36');
  12.  
  13.   // navigate to the target URL
  14.   await page.goto('http://httpbin.org/user-agent');
  15.  
  16.   // get the HTML text content
  17.   const htmlContent = await page.evaluate(() => document.body.textContent);
  18.  
  19.   // print the HTML content to the console
  20.   console.log(htmlContent);
  21.  
  22.   // close the browser
  23.   await browser.close();
  24. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement