async function link(keys) {
const browser = await puppeteer.launch({
ignoreHTTPSErrors: true,
headless: false,
devtools: false
})
const page = await browser.newPage()
let results = {}
console.log('keys', keys)
for (let key of keys) {
await page.goto(`https://btso.pw/search/${key}`)
// await page.waitFor(5000)
const result = await page.evaluate(() => {
var data = []
var t = document.querySelector('.data-list')
if (t) {
var a = t.getElementsByTagName('a')
for (var i = 0; i < a.length; i++) {
if (!a[i].className.match('btn')) {
data.push({
title: a[i].title,
maglink:
'magnet:?xt=urn:btih:' +
a[i].outerHTML
.replace(/.*hash\//, '')
.replace(/" .*\n.*\n.*\n.*/, ''),
size: a[i].nextElementSibling.textContent,
src: a[i].href
})
}
}
}
return data
})
results[key] = result
}
browser.close()
return results
}