-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
69 lines (52 loc) · 1.72 KB
/
index.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
63
64
65
66
67
68
69
//Dependencies
const Puppeteer_Stealth = require("puppeteer-extra-plugin-stealth")
const Puppeteer = require("puppeteer-extra")
///Configurations
//Puppeteer
Puppeteer.default.use(Puppeteer_Stealth())
//Main
async function get(url, headers = "", useragent = ""){
return new Promise(async(resolve) =>{
const browser = await Puppeteer.default.launch({ headless: false, args: ["--no-sandbox", "--disable-setuid-sandbox"] })
const page = await browser.newPage()
if(headers){
await page.setExtraHTTPHeaders(headers)
}
if(useragent){
await page.setUserAgent(useragent)
}
await page.goto(url, { waitUntil: "networkidle0" })
const page_content = await page.content()
await browser.close()
resolve(page_content)
})
}
async function post(url, post_body = "",headers = "", useragent = ""){
return new Promise(async(resolve) =>{
const browser = await Puppeteer.default.launch({ headless: false, args: ["--no-sandbox", "--disable-setuid-sandbox"] })
const page = await browser.newPage()
if(headers){
await page.setExtraHTTPHeaders(headers)
}
if(useragent){
await page.setUserAgent(useragent)
}
await page.setRequestInterception(true);
page.on("request", ir=>{
var data = {
"method": "POST",
"postData": post_body
}
ir.continue(data)
})
await page.goto(url, { waitUntil: "networkidle0" })
const page_content = await page.content()
await browser.close()
resolve(page_content)
})
}
//Exporter
module.exports = {
get: get,
post: post
}