1 Star 0 Fork 22

19357697002 / jsoup

forked from OpenHarmony-SIG / jsoup 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

jsoup

简介

jsoup支持根据URL、HTML文件、HTML字符串解析HTML;支持操作HTML元素、属性、文本;支持DOM遍历或CSS选择器查找和提取数据。

preview.gif

下载安装

npm install @ohos/jsoup --save

OpenHarmony npm环境配置等更多内容,请参考 如何安装OpenHarmony npm包

使用说明

  1. 引入依赖
  import { htmlparser } from '@ohos/jsoup/';
  import { htmlParser } from '@ohos/jsoup/'
  import { ParseHtml } from '@ohos/jsoup/'
  1. 解析HTML
const html = `
<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>Document</title>
</head>
<style>
   .tagh1{
       background-color: aquamarine;
       color:'blue';
   }
   .one-div{
       line-height: 30px;
   }
</style>
<body>
   <h1 class="tagh1">
       kkkk
       <p>hhhhh</p>
   </h1>
   <div style="color:red; height:100px;" class="one-div">cshi</div>
   <img src="https:baidu.com" alt="wwww"/>
   <p>wjdwekfe>>>>></p>
   <em>dsjfw<<<<<p
   <div>dksfmjk</div>
   owqkdo</em>
</body>
</html>
`
 const htmlParser = new parser(html)
 const dom = htmlParser.getHtmlJson()

接口说明

const parser = new htmlParser(html)

  1. 解析字符串类型的HTML parser.getHtmlJson()
  2. 提取CSS parser.getClassStyleJson()
  3. 解析文件类型的HTML ParseHtml.read_fileIo()

兼容性

支持 OpenHarmony API version 8 及以上版本。

目录结构

|---- jsoup  
|     |---- entry  # 示例代码文件夹
|        |----src
|           |----addTag.ets
|           |----index.ets
|     |---- jsoup  # jsoup库文件夹
|	    |----src
          |----main
              |----ets
                  |----common 模板
                  |----htmlparser/lib #html解析核心实现
                  |----js-parse-html #js方式的解析
                  |----parser-html-json #json方式的解析
                  |----ParseHtml.ets #解析html
|           |---- index.ets  # 对外接口
|     |---- README.MD  # 安装使用方法                    

贡献代码

使用过程中发现任何问题都可以提 Issue 给我们,当然,我们也非常欢迎你给我们发 PR

开源协议

本项目基于 MIT ,请自由地享受和参与开源。

The MIT License Copyright (c) 2009-2022 Jonathan Hedley <https://jsoup.org/> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/shenfei19357697002/jsoup.git
git@gitee.com:shenfei19357697002/jsoup.git
shenfei19357697002
jsoup
jsoup
master

搜索帮助