Skip to content

Instantly share code, notes, and snippets.

@omisolaidowu
Created January 30, 2024 19:54
Show Gist options
  • Save omisolaidowu/323747792f29d31d01c0d1b3edbb6e31 to your computer and use it in GitHub Desktop.
Save omisolaidowu/323747792f29d31d01c0d1b3edbb6e31 to your computer and use it in GitHub Desktop.
final code
// import the required libraries
const { Builder } = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
// set the path to udetected_chromedriver executable file
const chromeDriverPath = 'C:/Users/dell/AppData/Roaming/undetected_chromedriver/undetected_chromedriver.exe';
// set the path to your actual Chrome browser executable file
const chromeExePath = 'C:/Program Files/Google/Chrome/Application/chrome.exe';
// set Chrome options
const chromeOptions = new chrome.Options();
chromeOptions.setChromeBinaryPath(chromeExePath);
// run Chrome in headless mode
chromeOptions.addArguments('--headless');
// create a new WebDriver instance
const driver = new Builder()
.forBrowser('chrome')
.setChromeOptions(chromeOptions)
.setChromeService(new chrome.ServiceBuilder(chromeDriverPath))
.build();
// navigate to a website
async function scraper() {
try {
await driver.get('https://nowsecure.nl');
// extract the page HTML
const pageSource = await driver.getPageSource();
console.log('Page HTML:', pageSource);
// close the driver instance
await driver.quit();
} catch (error) {
console.error('An error occurred:', error);
}
}
// call the main function
scraper();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment