/** * Get templates names from VTEX admin HTML * @param {String} templateList HTML list of all templates * @returns {Array} with all template names on VTEX */ getTemplateNames(templateList) { const $ = cheerio.load(templateList); return $(`.template > div`).map(function() { return $(this).text(); }).get(); }
$(".BoxTable tr").map((i, element) => ({ time: $(element).find('td:nth-of-type(1)').text().trim(), rate: $(element).find('td:nth-of-type(2)').text().trim(), deep: $(element).find('td:nth-of-type(3)').text().trim(), number: $(element).find('td:nth-of-type(4)').text().trim(), location: $(element).find('td:nth-of-type(5)').text().trim() })).get()
async function requestGoogle(message, proxy) { const keyword = encodeURIComponent(`${message} site:stackoverflow.com`) const res = await fetch(`https://www.google.com/search?q=${keyword}`, { agent: getAgentFromProxy(proxy), }) const text = await res.text() const $ = cheerio.load(text) return $('h3.r>a').map(function () { const $this = $(this) return { title: $this.text(), href: $this.attr('href'), } }).get() }
$('#main .findit-item').map(function(i, el) { const findItemText = $(this).text(); // availability is end of item text const itemAvailabilityText = findItemText.substr(findItemText.lastIndexOf(" - ")+3); // if item text contains not holdable, format availability const formattedAvailability = /\-\ Not\ Holdable\ \-/.test(findItemText) ? `${ itemAvailabilityText } -- Not Holdable` : itemAvailabilityText; return formattedAvailability; }).get()
/** * Get all the departments. * * @returns {Promise<Department[]>} */ async function getAllDepartments() { const html = await httpService.consultaHorarios(); const $ = cheerio.load(html); return $('#departamento > option') .slice(1) .map((i, el) => { const parsedEl = $(el); return { code: parsedEl.val(), name: parsedEl.text() }; }) .get(); }
$('.repo-list li').get().map((li) => { try { const $li = $(li) const $link = $li.find('h3 a') const url = resolve(baseUrl, $link.attr('href')) const linkText = $link.text() const repoParts = linkText.split('/').map(p => p.trim()) const desc = $li.find('p').text().trim() return { url, userName: repoParts[0], repoName: repoParts[1], desc } } catch (err) { console.error('parse error: ', err) } }).filter(Boolean)
// Do this so we can reliably get the correct url. // Otherwise, the number could reference a PR or an issue. getUrlFromOP(ref) { const as = this.$('a'); const links = as.map((i, el) => this.$(el)).get(); for (const link of links) { const text = link.text(); if (text === ref) { const href = link.attr('href'); if (href) return href; } } }
$('#main .findit-item').map(function(i, el) { const findItemText = $(this).text(); // availability is end of item text const itemAvailabilityText = findItemText.substr(findItemText.lastIndexOf(" - ")+3); // if item text contains not holdable, format availability const formattedAvailability = /\-\ Not\ Holdable\ \-/.test(findItemText) ? `${ itemAvailabilityText } -- Not Holdable` : itemAvailabilityText; return formattedAvailability; }).get()
/** * Get all the levels. * * @returns {Promise<Level[]>} */ async function getAllLevels() { const html = await httpService.consultaHorarios(); const $ = cheerio.load(html); return $('#nivel > option') .slice(1) .map((i, el) => { const parsedEl = $(el); return { code: parsedEl.val(), name: parsedEl.text() }; }) .get(); }