-
Notifications
You must be signed in to change notification settings - Fork 3
/
WebScrapper.js
62 lines (53 loc) · 1.6 KB
/
WebScrapper.js
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
51
52
53
54
55
56
57
58
59
60
61
62
/**
*
* Website :- https://sh20raj.github.io/WebScrapperJS/ || https://wholly-api.appspages.online/ || https://sh20raj.gitbook.io/whollyapi
* GitHub :- https://github.com/SH20RAJ/WebScrapperJS/
* Repl :- https://replit.com/@SH20RAJ/WebScrapperJS/
*
*
*/
function scrapper(url){
var baseurl = 'https://wholly-api.skinnyrunner.com/get/website-data.php?get_html=';
this.url = url;
// make a new parser
this.parser = new DOMParser();
this.get = (a,b,c) => {
if(b) baseurl='';
if(!a) a = baseurl+''+url;else a=baseurl+''+a;
console.log(a);
var text;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
rpns = this.responseText;
text = rpns;
}
};
xhttp.open("GET", a,c);
xhttp.send();
return text;
}
this.gethtml = (a,b,c)=>{
return this.parser.parseFromString(this.get(a,b,c), "text/html") ;
}
this.getjson = (a)=>{
return JSON.parse(this.get(a));
}
this.fetch = (a)=>{
return this.get(a,true);
}
this.fetchjson = (a)=>{
return JSON.parse(this.get(a,true));
}
this.fetchhtml = (a)=>{
return this.parser.parseFromString(WebScrapper.get(a,true), "text/html");
}
this.getparam = (a,e) => { return e||(e=window.location.href),new URL(e).searchParams.get(a)};
this.getRandomInt = (min, max)=>~~(Math.random()*(max-min+1)+min);
//convert html string into DOM
//const document2 = parser.parseFromString(htmlStr, "text/html");
}
let WebScrapper = new scrapper();
if (typeof module !== 'undefined' && module.exports) {
module.exports = WebScrapper;
}