Advertisement
idowupaul

zenrows bypass

Jan 3rd, 2024
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.37 KB | Source Code | 0 0
  1. // import the required library
  2. const puppeteer = require('puppeteer');
  3.  
  4. const url = 'https://www.amazon.com/s?k=headphones';
  5.  
  6. (async () => {
  7.   const browser = await puppeteer.launch({ headless: 'new' });
  8.   const page = await browser.newPage();
  9.  
  10.   // intercept requests to modify them
  11.   await page.setRequestInterception(true);
  12.  
  13.   page.on('request', (request) => {
  14.     // modify the request to include params
  15.     const urlWithParams = new URL(request.url());
  16.     urlWithParams.searchParams.append('url', url);
  17.     urlWithParams.searchParams.append('apikey', '<YOUR_ZENROWS_API_KEY>');
  18.  
  19.     request.continue({ url: urlWithParams.toString() });
  20.   });
  21.  
  22.   try {
  23.     // navigate to the modified URL
  24.     const response = await page.goto(url);
  25.  
  26.     // check if the response is successful (status code 200)
  27.     if (response && response.status() === 200) {
  28.      
  29.       // extract data from the page
  30.       const extractedData = await page.evaluate(() => {
  31.         return {
  32.           // extract title text to further confirm access
  33.           title: document.querySelector('h1').textContent,
  34.         };
  35.       });
  36.  
  37.       console.log(extractedData);
  38.     } else {
  39.       console.error(`Failed to load the page. Status: ${response ? response.status() : 'unknown'}`);
  40.     }
  41.   } catch (error) {
  42.     console.error('Error:', error);
  43.   } finally {
  44.     await browser.close();
  45.   }
  46. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement