Skip to content

Instantly share code, notes, and snippets.

@jericbas
Created January 20, 2023 11:52
Show Gist options
  • Save jericbas/64cf9a1a0ec10e88d0779dfdd809604b to your computer and use it in GitHub Desktop.
Save jericbas/64cf9a1a0ec10e88d0779dfdd809604b to your computer and use it in GitHub Desktop.
Check if text is exist in the url
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