Update index.js
Browse files
index.js
CHANGED
|
@@ -54,43 +54,36 @@ function formatSize(num) {
|
|
| 54 |
}
|
| 55 |
|
| 56 |
async function xbuddy(url) {
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
args: ['--no-sandbox']
|
| 63 |
-
})
|
| 64 |
-
|
| 65 |
-
const context = await browser.newContext()
|
| 66 |
-
const page = await context.newPage()
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 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 |
-
|
| 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 |
+
}
|