Created
January 20, 2023 11:52
-
-
Save jericbas/64cf9a1a0ec10e88d0779dfdd809604b to your computer and use it in GitHub Desktop.
Check if text is exist in the url
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
const got = require('got'); | |
const { parse } = require('parse5'); | |
const fs = require('fs'); | |
const searchText = process.argv[2]; | |
const listFile = process.argv[3] || 'list.txt'; | |
fs.readFile(listFile, 'utf8', (err, data) => { | |
if (err) throw err; | |
const websiteList = data.split('\n'); | |
websiteList.forEach(async (website) => { | |
try { | |
const response = await got(website); | |
const document = parse(response.body); | |
const text = parse5.serialize(document); | |
if (text.includes(searchText)) { | |
console.log(`${website} contains the word '${searchText}'`); | |
} else { | |
console.log(`${website} does not contain the word '${searchText}'`); | |
} | |
} catch (error) { | |
console.log(error); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment