Git Product home page Git Product logo

nodes-cheerio--extract-html-content's Introduction

README

general

Use cheerio to parse html files as dom. The cheerio has the same api as jqeury. https://www.npmjs.com/package/cheerio

First read the local html as text, and parse it to cheerio, then use api of cheerio(just like jquery’s) to manupulate the content.

所有的题目都在hr元素的兄弟元素中。 因此先打到 hr元素(幸好整个文档中只有一个),然后使用nextAll获得所有后续的兄弟结点,最后用each遍历,用text获取文本。

乱码可能原因为fs.read函数有问题。

run

run ‘node a.js’ to generate unit1-8.txt run ‘node b.js’ to generate unit_answer1-8.txt.

Then Unit1-8.txt will be generated in current direcory.

答案从script中获取。网页中是写在script中的数组中的,先获取为string, 然后调用eval函数,则能够得到这个答案数组。对于task4, 答案是在这个元素中 ‘span.answerfont’, 因此直接获取这个元素的text,以数组返回就行了。

a.js和b.js有大量重复代码,因为是直接复制粘贴的。这样做最方便!!

knowledge point

nodejs 读取中文

fs模块不支持中文,使用iconv-lite模块即可。 http://blog.csdn.net/youbl/article/details/29812669

nodes-cheerio--extract-html-content's People

Contributors

astropeak avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.