async function getUUID(username) { const res = await got(`https://mcuuid.net/?q=${username}`); const $ = cheerio.load(res.body); const input = $('input')[1]; if (!input) { return; } return input.attribs['value']; }
// Append each element to the body context matches.map((index, element) => { elements.push({ name: element.name, attributes: element.attribs, html: $.html(element) }); });
/** * Scrapes summoner spells from a League of Graphs page * @param {cheerio} $ - The cheerio object */ scrapeSummonerSpells($) { if (Mana.gameClient.locale !== 'en_GB' && Mana.gameClient.locale !== 'en_US') { console.log(2, `[ProviderHandler] [League of Graphs] Summoner spells are not supported because you're not using the english language in League`); return []; } return $('h3:contains(Summoner Spells)').parent().find('img').toArray().filter(x => Object.values(Mana.gameClient.summonerSpells).find(z => z.name === x.attribs.alt)).map(x => Object.values(Mana.gameClient.summonerSpells).find(z => z.name === x.attribs.alt).id); }
function asciidoctorRenderer(data, locals) { var html = asciidoctor.convert(data.text, asciidoc_options); var $ = cheerio.load(html, cheerio_load_option); $('.highlight code').each(function(index, elem) { options.lang = elem.attribs['data-lang']; var code = entities.decodeXML($(elem).text()); var content = util.highlight(code, options); $(elem).html(content); }); return $.html() .replace(/{/g, '{') .replace(/}/g, '}'); }
getLinks () { return new Promise((resolve, reject) => { request.get('https://news.ycombinator.com/', (err, request, body) => { if (err) { return reject(err) } const $ = cheerio.load(body) const links = [] $('.title a[href^="http"], a[href^="https"]').each((index, element) => { if (element.attribs.class) links.push($(element)) }) return resolve({ links }) }) }) }
function fetchIds(document) { const $ = cheerio.load(document.toString()); const links = $('a'); const validUrls = []; for(let i = 0; i < links.length; i++) { const link = links[i]; const href = link.attribs.href; if (href.includes("https://www.youtube.com/watch?v=")) { validUrls.push(href.replace("https://www.youtube.com/watch?v=", "")); } } return validUrls; }
/** * Get URL-referenced images in a GMail message * @param message The GMail message to extract images from * @returns A list of image URLs */ const _getImageUrls = (message) => { const unpack = (x) => { return Buffer.from(x.body.data || '', 'base64').toString(); }; // Get message's HTML let rawHtml = message.payload.parts.map( p => unpack(p) ).join(''); rawHtml += unpack(message.payload); // Return image URLs return cheerio.load(rawHtml)('img') .toArray() .map(image => image.attribs.src); }
lists.map((index, list) => { let titleObj = $(list).find('.title a'); let title = titleObj.text(); let originUrl = origin + titleObj.attr('href'); let metaAuthor = $(list).find('.author a:first-child').text(); let metaTime = $(list).find('.author .split')[0].nextSibling.nodeValue; let avatarUrl = $(list).find('.author img').attr('src'); let a = $(list).find('.author a')[1]; let subjectUrl = origin + a.attribs.href; let subjectText = $(a).text(); return { listTitle:title, listOriginUrl: originUrl, listMetaAuthor: metaAuthor, listTime: metaTime, listAvatarUrl: avatarUrl, listSubjectUrl: subjectUrl, listSubjectText: subjectText }; })
const parseCategories = (html) => { let categories = []; const $ = cheerio.load(html); const htmlCategories = $.html('#subcatpromo div'); $(htmlCategories).map((index, data) => { categories.push(data.firstChild.attribs.title) }); return categories; }
// private function responsible for fetching IDs after parsing provided html. function fetchIDs(url, fetchIDsCompleted) { request(url, function (error, response, body) { if (!error && response.statusCode == 200) { var $c = cheerio.load(body); var wallpaperThumbs = []; $c("figure[data-wallpaper-id]").each(function (i, element) { wallpaperThumbs.push({ id: $c(element).attr('data-wallpaper-id'), ext: $c(element).find("img").attr("data-src").substr($c(this).length - 4), res: $c(element).find(".wall-res").text(), sfw: element.attribs['class'].indexOf('sfw') > 0, sketchy: element.attribs['class'].indexOf('sketchy') > 0, nsfw: element.attribs['class'].indexOf('nsfw') > 0 }); }); //updating URLs for the thumbnails and wallpapers. for (var i in wallpaperThumbs) { wallpaperThumbs[i].thumbnailUrl = getThumbnailUrl(wallpaperThumbs[i].id, wallpaperThumbs[i].ext); } fetchIDsCompleted(wallpaperThumbs); } else { fetchIDsCompleted(null); } }); }
function parseIdolsUtils(body) { const $ = cheerio.load(body); const $div = $('.ak-nocontentpadding')[1].children; for (let i = 0; i < $div.length; i++) { if ($div[i].type !== 'div') { $div.splice(i, 1); } } for (let i = 0; i < $div.length; i++) { for (let j = 0; j < $div[i].children.length; j++) { const $actual = $div[i].children[j]; if ($actual.type == 'tag' && $actual.name == 'div' && $actual.attribs.class == 'ak-panel-content') { if (i == 0) { item.description = $actual.children[0].data.replace(/\n/g, ''); } else if (i == 2) { item.spell = $actual.children[0].data.replace(/\n/g, ''); } } } } }
const parsePromotion = (html) => { const ids = []; const $ = cheerio.load(html); const htmlPromotions = $.html('#promolain li a'); $(htmlPromotions).map((index, data) => { const href = data.attribs.href.split("="); const id = href[href.length - 1]; ids.push(id); }); return ids; }