-
-
Save Piterden/47fc80fe942024978c572a3001061d27 to your computer and use it in GitHub Desktop.
Shittycode )))
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const puppeteer = require('puppeteer') | |
let anime = {} | |
async function run (searched) { | |
searched = searched.replace(';', ' ') | |
// Setup pupeteer | |
const browser = await puppeteer.launch({ | |
headless: false, | |
}) | |
const page = await browser.newPage() | |
// Connect to Anitokyo | |
try { | |
await page.goto('http://anitokyo.tv/index.php?do=multisearch', { | |
timeout: 10000, | |
waitUntil: 'domcontentloaded', | |
}) | |
} catch (err) { | |
await console.log('Тут эррор') | |
await CloseBrowser() | |
} | |
await page.click('#story') | |
await page.type('#story', searched) | |
await page.click('input[value="Поиск"]') | |
await page.waitForSelector('.content') | |
let Output = await page.evaluate(() => { | |
let years = document | |
.querySelectorAll('.story')[0] | |
.querySelector('.reset > li:nth-child(3)> a').innerHTML | |
let nmu = 0 | |
for (let i = 0; i < document.querySelectorAll('.story').length - 1; i++) { | |
if ( | |
document.querySelectorAll('.story')[i].querySelector('.reset > li:nth-child(3)> a').innerHTML < years | |
) { | |
years = document | |
.querySelectorAll('.story') | |
[i].querySelector('.reset > li:nth-child(3)> a').innerHTML | |
nmu = i | |
} | |
} | |
return document | |
.querySelectorAll('.story') | |
[nmu].querySelector('.story_h > a').href | |
}) | |
if (Output === '') { | |
console.log('Неверное имя') | |
return await CloseBrowser() | |
} | |
let link = await Output | |
// await console.log('[API] Link: ' + Output) | |
try { | |
await page.goto(Output) | |
} catch (err) { | |
await console.log('Тут эррор') | |
await CloseBrowser() | |
} | |
anime = await page.evaluate(() => { | |
let genres = ' ' | |
for ( | |
let i = 0; | |
i < document | |
.querySelector('#dle-content > article > div.story_c > ul > li:nth-child(4)') | |
.querySelectorAll('a').length; | |
i++ | |
) { | |
genres += document | |
.querySelector('#dle-content > article > div.story_c > ul > li:nth-child(4)') | |
.querySelectorAll('a')[i].innerHTML + ' ' | |
} | |
return { | |
name: document.querySelector('.story_h').innerHTML, | |
fullnames: document.querySelector('.reset').querySelector('b').innerHTML, | |
cover: document.querySelector('.poster').querySelector('a').href, | |
genre: genres, | |
age: document.querySelector('#dle-content > article > div.story_c > ul > li:nth-child(13) > span > a').innerHTML, | |
} | |
}) | |
anime.url = { | |
anitokyo: link, | |
shikimori: '', | |
} | |
await console.log(anime) | |
async function CloseBrowser () { | |
await browser.close() | |
} | |
await CloseBrowser() | |
} | |
// run('Boku no hero academia') | |
// setTimeout(function () { | |
run('SteinsGate') | |
// },8000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment