Created
January 30, 2024 19:54
-
-
Save omisolaidowu/323747792f29d31d01c0d1b3edbb6e31 to your computer and use it in GitHub Desktop.
final code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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