Skip to content

Instantly share code, notes, and snippets.

@SarahElson
Last active September 15, 2022 06:04
Show Gist options
  • Save SarahElson/bf42ed35613f185acebeb1354a456b24 to your computer and use it in GitHub Desktop.
Save SarahElson/bf42ed35613f185acebeb1354a456b24 to your computer and use it in GitHub Desktop.
How To Perform Web Scraping With JavaScript And Selenium
async function getVideos(videos) {
let videoDetails = [];
try {
for (const video of videos) {
const title = await video.findElement(By.id('video-title')).getText();
const views = await video
.findElement(By.xpath(".//*[@id='metadata-line']/span[1]"))
.getText();
const date = await video
.findElement(By.xpath(".//*[@id='metadata-line']/span[2]"))
.getText();
videoDetails.push({
title: title ?? '',
views: views ?? '',
publishedDate: date ?? '',
});
}
} catch (error) {
console.log(error);
}
return videoDetails;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment