Repository navigation
Expand file tree
/
Copy pathfirsttask.js
More file actions
50 lines (42 loc) · 1.42 KB
/
Copy pathfirsttask.js
File metadata and controls
50 lines (42 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import fetch from "node-fetch";
let inputDomain = "https://antstack.com"; // domain name can be modified...
let inputName = "description"; // metatag name can be modified according...
const response = await fetch(inputDomain);
const htmlInStr = await response.text();
const validateString = (index) => {
if(index != -1) {
return true;
}
return false;
}
const getElementWithinQuotes = (string,startIndex) => {
let posOfFirstQuote = string.indexOf('"', startIndex+1);
let posOfNextQuote = string.indexOf('"', posOfFirstQuote+1);
let elementWithinQuotes = string.slice(posOfFirstQuote+1, posOfNextQuote);
return elementWithinQuotes;
}
let istart = htmlInStr.indexOf("<meta");
let flag = 0;
while(validateString(istart))
{
let iend = htmlInStr.indexOf(">", istart+1);
iend += 1;
let meta = htmlInStr.slice(istart, iend);
let indexOfName = meta.indexOf("name");
let contentStr = "";
if(validateString(indexOfName)) {
let tagName = getElementWithinQuotes(meta, indexOfName);
if(tagName === inputName) {
let indexOfContent = meta.indexOf("content");
if(validateString(indexOfContent)) {
contentStr = contentStr + getElementWithinQuotes(meta, indexOfContent);
}
console.log("Content ::", contentStr);
flag = 1;
}
}
istart = htmlInStr.indexOf("<meta", iend);
}
if(flag === 0) {
console.log("meta not present");
}