Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

# Write javascript code using selenium to scrape this website

"https://www.reddit.com/". Use Chrome webdriver.


# Set the path for the webdriver to "C:\Program Files\Google\Chrome\Application"
# Locate the element "div" with class "rpBJOHq2PR60pnwJlUyP0". Scape all the "h3"
elements inside.
Copy code

---------------
const {Builder, By, Key, until} = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');

let driver = new Builder()


.forBrowser('chrome')
.setChromeOptions(new chrome.Options().setBinaryPath("C:\\Program Files\\
Google\\Chrome\\Application"))
.build();

driver.get('https://www.reddit.com/');

const divElement = driver.findElement(By.className("rpBJOHq2PR60pnwJlUyP0"));


const h3Elements = divElement.findElements(By.tagName("h3"));

h3Elements.then(function(elements) {
elements.forEach(function(element) {
element.getText().then(function(text) {
console.log(text);
});
});
});

driver.quit();

You might also like