Node-jquery, an HTML analysis tool on node

Source: Internet
Author: User
First, describe the scenario that generates this article: I need to obtain the latest JavascriptCoverage built by the project in jenkins, which is displayed on the project situation Report for the management level, however, because jenkins does not directly use APIs to obtain data, we can only send data from self-built containers... syntaxHighlighter. all first describes the scenario where this article was created: I need to obtain the project's latest Javascript Coverage built in jenkins, which is displayed on the project situation Report displayed at the management level, however, because jenkins does not directly use APIs to obtain data, we can only release Javascript Coverage data APIs from self-built containers for Report projects. Because simple data analysis is used, only the Host is a simple web Server, so I do not like Tomcat, large tools such as IIS, it seems a bit cool with a knife, shift. I prefer simple web containers such as node. js. Therefore, the project uses node. js, and the natural javascript and html operations of node. js are integrated. The DOM structure makes Html parsing easier and more concise. Node. js parses html dom by htmlpaser and jsdom. However, I personally prefer the jQuery style and the unified API of web jQuery, so I chose node-jquery. The code is deployed in the Github https://github.com/coolaj86/node-jquery Below is a simple demo: capture the Github Popular project and print it out on the console. Var $ = require ('jquery '); String. format = function () {var s = arguments [0]; for (var I = 0; I <arguments. length-1; I ++) {var reg = new RegExp ("\\{" + I + "\\\}", "gm"); s = s. replace (reg, arguments [I + 1]);} return s ;}; $. get (" https://github.com/popular/forked ", Function (html) {var $ doc = $ (html); console. log ("No. name language star forks ") $ doc. find ("ul. repolist li. source "). each (function (I, project) {var $ project = $ (project); var name = $ project. find ("h3 "). text (). trim (); var language = $ project. find ("li: eq (0 )"). text (). trim (); var star = $ project. find ("li. stargazers "). text (). trim (); var forks = $ project. find ("li. forks "). text (). trim (); var row = String. format ("{4} {0} {1} {2} {3}", name, language, star, forks, I + 1); console. log (row );});});
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.