akkun3704 commited on
Commit
e8fb8e9
·
1 Parent(s): 6571f35

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +29 -36
index.js CHANGED
@@ -54,43 +54,36 @@ function formatSize(num) {
54
  }
55
 
56
  async function xbuddy(url) {
57
- let browser
58
- try {
59
- browser = await chromium.launch({
60
- headless: true,
61
- executablePath: '/usr/bin/chromium',
62
- args: ['--no-sandbox']
63
- })
64
-
65
- const context = await browser.newContext()
66
- const page = await context.newPage()
67
 
68
- await page.goto(`https://9xbuddy.in/process?url=${url}`)
69
-
70
- const response = await page.waitForResponse(res =>
71
- res.url().includes('extract') && res.request().method() === 'POST')
72
-
73
- const json = await response.json()
 
 
 
 
 
 
 
74
 
75
- if (json.status) {
76
- const html = await page.content()
77
- const $ = cheerio.load(html)
78
-
79
- const result = $('.text-sm.tracking-wide.px-3.py-3').get().map(el => ({
80
- type: $(el).find('.w-24').text(),
81
- q: $(el).find('.truncate').text(),
82
- size: $(el).find('.w-full div:nth-child(2)').text(),
83
- url: $(el).find('a').attr('href')
84
- })).filter(c => /^http/.test(c.url))
85
-
86
- json.response.result = result
87
- }
88
 
89
- return json
90
- } catch (e) {
91
- console.log(e)
92
- throw e
93
- } finally {
94
- await browser?.close?.()
95
  }
96
- }
 
 
 
 
54
  }
55
 
56
  async function xbuddy(url) {
57
+ const browser = await chromium.launch({
58
+ headless: true,
59
+ executablePath: '/usr/bin/chromium',
60
+ args: ['--no-sandbox']
61
+ })
 
 
 
 
 
62
 
63
+ const context = await browser.newContext()
64
+ const page = await context.newPage()
65
+
66
+ await page.goto(`https://9xbuddy.in/process?url=${url}`)
67
+
68
+ const response = await page.waitForResponse(res =>
69
+ res.url().includes('extract') && res.request().method() === 'POST')
70
+
71
+ const json = await response.json()
72
+
73
+ if (json.status) {
74
+ const html = await page.content()
75
+ const $ = cheerio.load(html)
76
 
77
+ const result = $('.text-sm.tracking-wide.px-3.py-3').get().map(el => ({
78
+ type: $(el).find('.w-24').text(),
79
+ q: $(el).find('.truncate').text(),
80
+ size: $(el).find('.w-full div:nth-child(2)').text(),
81
+ url: $(el).find('a').attr('href')
82
+ })).filter(c => /^http/.test(c.url))
 
 
 
 
 
 
 
83
 
84
+ json.response.result = result
 
 
 
 
 
85
  }
86
+
87
+ await browser.close()
88
+ return json
89
+ }