How to use the cheerio.load function in cheerio

To help you get started, we’ve selected a few cheerio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github msavy / gitbook-plugin-asciidoc-admonition-icons / index.js View on Github external
page.sections.forEach((section) => {
                if (section == undefined || section.content == undefined) {
                    return true;
                }
                $ = cheerio.load(section.content);
                // Find asciidoc admonition block.
                $(".admonitionblock").each(function () {
                    $this = $(this);
                    // Look at classes, should include the admonition type along with other irrelevant stuff.
                    candidateClasses = $(this)[0].attribs.class.split(/\s+/);
                    // Find the admonition class
                    admonClass = candidateClasses.find(klazz => options[klazz]);
                    // Skip if no relevant candidate found
                    if (admonClass === undefined) {
                        return true;
	    	        }
                    // Admonishment
                    admon = options[admonClass];
                    // Replacement we'll sub in.
                    iconElem = $("<div></div>")
                        .addClass(admon.classes)
github JpEncausse / WSRNodeJS / plugins / dictionary / dictionary.js View on Github external
var parse = function(html, word){
  var $ = require('cheerio').load(html);
  var ok = false;
  
  $('#TableHTMLResult .ldcomIN').each(function(){
    var value = $(this).text().trim();
    var match = matcher(value); 
    
    // console.log('['+value+']', 'match=', match, 'ok=', ok);
    if (ok && !match){ ok = value;   return false; } // Break loop
    if (match){        ok = value; // Will take next value 
      if (value.indexOf(word) == 0){ return false; }
    }
  });
  return ok;
}
github populr-app / populr / server / workers / websiteScraper.js View on Github external
request(url, function(error, response, body){
      // loads page into jquery
      var $ = cheerio.load(body);

      // selects human readable text
      var text = $('body').text();

      // Jquery alternative to remove tags
      // text = body.replace(/(&lt;([^&gt;]+)&gt;)/ig, '');

      // removes large whitespaces
      text = text.replace(/\s+/g, ' ');

      // removes non alpha-numeric characters
      text = text.replace(/[^\w\s]/gi, '');

      // white to file
      write(text);
      console.log('Writing Data for: ' + url);
github DIYgod / RSSHub / lib / routes / ltaaa / main.js View on Github external
target = 'ul.vmonth';
            break;
        case 'year':
            target = 'ul.vyear';
            break;
        default:
            target = 'ul.wlist';
    }

    const list_url = base_url + '/wtfy.html';
    const response = await got({
        method: 'get',
        url: list_url,
    });
    const data = response.data; // content is html format
    const $ = cheerio.load(data);

    // get urls
    const detail_urls = [];

    let a = $(target).find('a.rtitle');
    if (!a || a.length &lt;= 0) {
        a = $(target).find('div.li-title &gt; a');
    }

    for (let i = 0; i &lt; a.length; ++i) {
        const tmp = $(a[i]).attr('href');
        detail_urls.push(tmp);
    }

    // get articles
    const article_list = await Promise.all(detail_urls.map((url) =&gt; get_article(url)));
github philbot9 / youtube-comments-task / test / integration-tests / comment-page-stream.js View on Github external
results.forEach(html => {
            const $ = cheerio.load(html)
            expect($('.comment-thread-renderer').length).to.be.above(1)
            expect($('.comment-renderer').length).to.be.above(1)
          })
          done()
github jus / jus / test / jus.js View on Github external
before(function(done) {
        var page = pages['/other/index.md']
        $input = cheerio.load(page.input)
        page.render(context, function(err, output){
          $output = cheerio.load(output)
          done()
        })
      })
github BingKui / Crawler-Douban-Book / router / books.js View on Github external
request(docs[index].url, (error, response, body) =&gt; {
						logger.info('statusCode===&gt;' + response.statusCode);
						if (!error &amp;&amp; response.statusCode == 200) {
							let $ = cheerio.load(body);
							let _info = $('#info').html().split('<br>');
							let _name = $('#wrapper').find('h1').text().trim();
							logger.info('BookName: ' + _name);
							//logger.info($('#link-report').find('.intro').text());
							var _desc = $('#link-report').find('.intro').find('p');
							let de = [];
							for (let i = 0; i &lt; _desc.length; i++) {
								de.push($(_desc[i]).text().trim())
							}
							let _item = {
								name: _name,
								pic: $('#mainpic').find('.nbg').attr('href'),
								star: parseFloat($('#interest_sectl').find('.rating_num').text().trim()),
								desc: de,
								author: '',
								press: '',
github umijs / plugins / packages / @umijs / plugin-prerender / src / utils.ts View on Github external
export const _getDocumentHandler = (html: string, option?: object): CheerioStatic => {
  return cheerio.load(html, {
    decodeEntities: false,
    recognizeSelfClosing: true,
    ...option,
  });
}
github Westbrook / feather-icon-literals / bin / build.js View on Github external
icons.forEach(i =&gt; {
    const svg = fs.readFileSync(i, 'utf-8');
    const id = path.basename(i, '.svg');
    const ComponentName = (id === 'github') ? 'GitHub' : Case.pascal(id);
    const $ = cheerio.load(svg, {
      xmlMode: true,
    });
    const title = Case.capital(id);
    const fileName = path.basename(i).replace('.svg', '.js');
    const location = path.join(rootDir, 'lib/icons', fileName);

    $('*').each((index, el) =&gt; {
      if (el.name === 'svg') {
        $(el).prepend('