Created
July 18, 2022 16:55
-
-
Save SarahElson/e464f8d686659f5c26b8da959c18c48a 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
app.get('/', async (request, response) => { | |
// Web Scraping Code here | |
try { | |
const data = await WebScrapingLocalTest(); | |
response.status(200).json(data); | |
} catch (error) { | |
response.status(500).json({ | |
message: 'Server error occurred', | |
}); | |
} | |
}); | |
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment