Last active
September 15, 2022 06:04
-
-
Save SarahElson/bf42ed35613f185acebeb1354a456b24 to your computer and use it in GitHub Desktop.
How To Perform Web Scraping With JavaScript And Selenium
This file contains hidden or 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
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