Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const cheerio = require("cheerio")
- async function thsearch(query) {
- const baseUrl = 'https://en.thehentai.net';
- const encodedQuery = encodeURIComponent(query.trim());
- const url = baseUrl + '/?s=' + encodedQuery + '&utm_source=TheHentaiSearch&utm_medium=' + encodedQuery;
- const response = await fetch(url);
- const html = await response.text();
- const $ = cheerio.load(html);
- const heading = $('h2').first().text().trim();
- const resultsText = heading || '';
- const ads = [];
- $('div[style*="display:flex; margin:20px 0;"]').each((i, elem) => {
- let imgSrc = $(elem).find('img').attr('src') || null;
- if (imgSrc && imgSrc.startsWith('/')) {
- imgSrc = baseUrl + imgSrc;
- }
- ads.push({ imgSrc });
- });
- const posts = [];
- $('.gridPosts').each((i, elem) => {
- const $post = $(elem);
- const linkEl = $post.find('h3 a');
- const href = linkEl.attr('href') || null;
- const title = linkEl.attr('title') || null;
- let imgSrc = $post.find('div.img_cage img').attr('src') || null;
- if (imgSrc && imgSrc.startsWith('/')) {
- imgSrc = baseUrl + imgSrc;
- }
- const viewsText = $post.find('.postViews').text().trim() || '';
- const dateText = $post.find('.dataPost a').attr('title') || '';
- posts.push({
- url: href ? baseUrl + href : null,
- title,
- imgSrc,
- views: viewsText,
- date: dateText
- });
- });
- return {
- resultsText,
- posts
- };
- }
- //use
- const ttk = await thsearch("marin kitagawa")
- console.log(JSON.stringify(ttk, null, 2));
Advertisement