Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import * as cheerio from 'cheerio'
- import axios from 'axios'
- const instance = axios.create({
- timeout: 60000,
- headers: {
- 'origin': 'https://noted.lol',
- 'referer': 'https://noted.lol/'
- }
- })
- interface Homepage {
- creator: string,
- status: boolean,
- msg?: string,
- data?: any
- }
- class Noted {
- baseUrl: string
- creator: string
- constructor() {
- this.baseUrl = 'https://noted.lol'
- this.creator = '@neoxr.js - Wildan Izzudin'
- }
- homepage = (): Promise<Homepage> => new Promise(async (resolve) => {
- try {
- const html = await (await instance.get(this.baseUrl)).data
- const $ = cheerio.load(html)
- const data: {
- thumbnail?: string,
- title: string,
- read: string,
- author: {
- avatar?: string,
- name: string,
- about: string
- },
- url?: string
- }[] = []
- $('ul.posts-list').find('li').each((i: number, e: any) => {
- const title = $(e).find('h3.card-post-title').text()
- if (title) data.push({
- thumbnail: this.baseUrl + $(e).find('picture > img').attr('src'),
- title,
- read: $(e).find('.card-post-time').text(),
- author: {
- avatar: $(e).find('.tooltip-custom-author > a > picture > img').attr('src'),
- name: $(e).find('.tooltip-custom-author > a').text()?.trim(),
- about: $(e).find('.tooltip-custom-author > div').text()?.trim()
- },
- url: this.baseUrl + $(e).find('a').attr('href')
- })
- })
- if (!data.length) throw new Error('Data not found')
- resolve({
- creator: this.creator,
- status: true,
- data
- })
- } catch (e: any) {
- resolve({
- creator: this.creator,
- status: false,
- msg: e.message
- })
- }
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement