zoukankan      html  css  js  c++  java
  • cheerio 服务器端的jquery

    cheerio

    https://cheerio.js.org/

    Fast, flexible, and lean implementation of core jQuery designed specifically for the server.

    Features

    ❤ Familiar syntax: Cheerio implements a subset of core jQuery. Cheerio removes all the DOM inconsistencies and browser cruft from the jQuery library, revealing its truly gorgeous API.

    ϟ Blazingly fast: Cheerio works with a very simple, consistent DOM model. As a result parsing, manipulating, and rendering are incredibly efficient.

    ❁ Incredibly flexible: Cheerio wraps around @FB55’s forgiving htmlparser2. Cheerio can parse nearly any HTML or XML document.

    例子

    const cheerio = require('cheerio');
    const $ = cheerio.load('<ul id="fruits">...</ul>');
    

    $('.apple', '#fruits').text()
    //=> Apple
    
    $('ul .pear').attr('class')
    //=> pear
    
    $('li[class=orange]').html()
    //=> Orange
    

    用处

    可以用作服务器端的网页爬虫, 解析前端的静态页面。

    因为一般页面的主页都使用静态页面, 来提高SEO, 和首屏的页面相应度。使用这种工具正好可以应对, 静态页面解析, 提取有用数据。

    还可以处理静态页面, 给静态页面添加一些页面元素,或者脚本, 在代理的角色中,对往来网页做修改。

    其它

    Cheerio is not a web browser

    Cheerio parses markup and provides an API for traversing/manipulating the resulting data structure. It does not interpret the result as a web browser does. Specifically, it does not produce a visual rendering, apply CSS, load external resources, or execute JavaScript. If your use case requires any of this functionality, you should consider projects like PhantomJS or JSDom.

  • 相关阅读:
    第十五章:Spring Boot 与 开发热部署
    第一章:(1)分布式基础理论
    第一章:(4)Dubbo 案例 HelloWorld
    第一章:(2)Dubbo核心概念
    第十四章:(3)Spring Boot 与 分布式 之 SpringCloud
    web安全测试AppScan扫描工具
    Cheatsheet: 2013 02.01 ~ 02.15
    Cheatsheet: 2013 04.17 ~ 04.30
    Cheatsheet: 2013 02.16 ~ 02.28
    Cheatsheet: 2013 01.21 ~ 01.31
  • 原文地址:https://www.cnblogs.com/lightsong/p/10903136.html
Copyright © 2011-2022 走看看