Skip to content

Podul/XParser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

XParser

基于libxml2 的 html 解析

Usage

  1. 创建Document
let doc = Document("path")
  1. 查找,可使用XPath语法
// 标签名
doc.title()?.name

// 内容
doc.title()?.content
doc.div.div.h2.span["@id='Welcome_to_the_iPhone_Wiki'"]?.content

// 使用 XPath 方式
doc.meta(custom: "[@name='generator']")?.get("content")

// 获取属性
doc.meta[custom: "[@name='generator']"]?.get("content")
doc.meta["@name='generator'"]?.get("content")
doc.html.head.link(["rel": "search", "type": "application/opensearchdescription+xml"])?.get("title")

// 获取当前标签所有属性
doc.html()?.attributes

// 获取当前节点的所有子节点
doc.html()?.children

// 获取当前节点的4个兄弟节点
doc.html.head()?.child?[4]

不了解XPath的可以前往w3school学习了解.

Requirements

  • iOS 10.0+
  • MacOS 10.12+
  • Xcode 11.4+
  • Swift 5.2+

Swift Package Manager

.package(url: "https://github.com/podul/XParser", .branch("master"))

注意

由于Xcode 11.4才支持import libxml2,所以Xcode最低支持版本为11.4。目前为beta版,需前往开发者网站下载。

Author

Podul, ylpodul@gmail.com

License

XParser is available under the MIT license. See the LICENSE file for more info.

About

基于libxml2 的 html 解析

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages