Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const cheerio = require('cheerio')
- const puppeteer = require('puppeteer')
- const iPhone = puppeteer.devices['iPhone 12']
- module.exports = async q => {
- const browser = await puppeteer.launch({
- headless: 'new',
- args: [
- "--fast-start",
- "--disable-extensions",
- "--no-sandbox",
- "--disable-setuid-sandbox",
- "--no-gpu",
- "--disable-background-timer-throttling",
- "--disable-renderer-backgrounding",
- "--override-plugin-power-saver-for-testing=never",
- "--disable-extensions-http-throttling",
- ]
- })
- try {
- const page = await browser.newPage()
- await page.emulate(iPhone)
- await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3');
- await page.setExtraHTTPHeaders({
- cookie: 'your_cookie_here'
- })
- await page.goto('https://character.ai/', {
- waitUntil: 'networkidle2',
- timeout: 0
- })
- await page.type('input[placeholder="Search for Characters"]', q)
- await page.keyboard.press('Enter')
- await page.waitForTimeout(1200)
- const html = await page.content()
- await browser.close()
- const $ = cheerio.load(html)
- const data = []
- $('div[class="flex flex-col sm:gap-3 w-full h-full overflow-y-auto overflow-x-hidden"]').find('a[class="group flex w-full flex-row justify-between hover:bg-surface-elevation-3 hover:rounded-spacing-m p-2 items-center"]').each((i,e) => data.push($(e).attr('href').split`/`[2]))
- if (data.length < 1) return ({
- status: false,
- msg: '[Character.AI]: I can\'t find the character!'
- })
- const result = data.splice(0, 20)
- return ({
- status: true,
- data: result
- })
- } catch (e) {
- await browser.close()
- return ({
- status: false,
- msg: '[Character.AI]: ' + e.message
- })
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement