# parse5-find-child **Repository Path**: Halliwood/parse5-find-child ## Basic Information - **Project Name**: parse5-find-child - **Description**: A tool to find child element from document parsed by parse5. - **Primary Language**: TypeScript - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-08-18 - **Last Updated**: 2023-04-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # parse5-find-child #### 介绍 一个在[parse5](https://www.npmjs.com/package/parse5)解析后的网页文档中,通过路径查找相关节点的工具,支持精确路径匹配和模糊路径匹配。 #### 安装 ``` npm i parse5-find-child -S ``` #### 使用说明 假定需要查找的html文档如下所示: ```html parse5-find-child test example Big Boat
Personal information: Name:
E-mail:
Date of birth:
First Name: Bill Gates
Telephone: 555 77 854
Telephone: 555 77 855
``` 通过指定路径查找节点,多层级路径用`;`隔开。 每层路径支持4种查找方式,可联合使用多种方式,用`,`隔开: * 元素类型,比如`
` * class属性,比如`.list-wrapper` * id属性,比如`#fruit` * 通配符`*` 可指定精确路径,比如`;
;
`。 也可使用通配符`*`指定模糊路径,比如`.list-wrapper2;*;
  • `。 #### 示例 ```typescript import { parse } from 'parse5' import findChild from 'parse5-find-child' // 字符串html来自上述html文档 const doc = parse(html) // 查找id为contact的节点 const theContactTable = findChild(doc, '#contact') // 查找class为list-wrapper的节点 const theListWrapperDiv = findChild(doc, '.list-wrapper') // 查找class为list-wrapper2的节点的所有li子节点 const out = findChild(doc, '.list-wrapper2;*;
  • ') ```