go第三方库文档 html处理 goquery

//go第三方库文档 html处理 goquery
//地址
https://pkg.go.dev/github.com/PuerkitoBio/goquery#section-readme

// goquery-有点像那个j型的东西,只在围棋中
// 生成状态Go参考Sourcegraph徽章
// goquery为Go语言带来了类似于jQuery的语法和一组特性。它基于Go的net/html包和CSS选择器库cascadia。由于net/html解析器返回节点,而不是功能齐全的DOM树,因此jQuery的有状态操作函数(如height()、css()、detach())已被取消。
// 另外,由于net/html解析器需要UTF-8编码,goquery也需要UTF-8编码:调用者有责任确保源文档提供UTF-8编码的html。请参阅wiki以了解执行此操作的各种选项。
// 在语法方面,它尽可能接近jQuery,尽可能使用相同的函数名,以及温暖和模糊的可链接接口。jQuery是一个非常流行的库,我觉得编写一个类似的HTML操作库最好遵循它的API而不是重新开始(与Go的fmt包的精神相同),尽管它的一些方法不够直观(看看你,index()…)。

// 目录
// 安装
// 变更日志
// 美国石油学会
// 例子
// 相关项目
// 支持
// 许可证

// 安装
// 请注意,由于net/html依赖关系,goquery需要Go1.1+,并在Go1.7+上进行测试。
// $go get github.com/purkitobio/goquery

// (可选)要运行单元测试:
// $cd$GOPATH/src/github.com/purkitobio/goquery
// $go test

// (可选)运行基准测试(警告:运行几分钟):
// $cd$GOPATH/src/github.com/purkitobio/goquery
$ go test -bench=".*"


// 变更日志
// 请注意,goquery的API现在是稳定的,不会中断。

// 2021-10-25(v1.8.0):添加渲染函数以将选择渲染到io.Writer(感谢@anthonygedeon)。
// 2021-07-11(v1.7.1):更新go.mod依赖项并添加可信性配置(谢谢@jauderho)。
// 2021-06-14(v1.7.0):添加Single和SingleMatcher函数以优化首次匹配选择(感谢@gdollardollar)。
// 2021-01-11(v1.6.1):修复在包含非元素节点的选择上调用{Prepend,Append,Set}Html时出现的恐慌。
// 2020-10-08(v1.6.0):在容器节点的上下文中解析所有处理html字符串(AfterHtml、AppendHtml等)的函数的html。感谢@thiemok和@davidjwilkins在这方面的工作。
// 2020-02-04(v1.5.1):更新模块依赖项。
// 2018-11-15(v1.5.0):Go模块支持(感谢@Zaba505)。
// 2018-06-07(v1.4.1):从Reader示例中添加新文档。
// 2018-03-24(v1.4.0):反对使用新文档(url)和新文档FromResponse(response)。
// 2018-01-28(v1.3.0):将ToEnd常量添加到切片,直到选择结束(感谢@davidjwilkins提出此问题)。
// 2018-01-11(v1.2.0):添加AddBack*和deprecate and self(感谢@davidjwilkins)。
// 2017-02-12(v1.1.0):添加SetHtml和SetText(感谢@glebtv)。
// 2016-12-29(v1.0.2):优化选择分配。文本(感谢@radovskyb)。
// 2016-08-28(v1.0.1):优化大型文档的性能。
// 2016-07-27(v1.0.0):标记版本1.0.0。
// 2016-06-15:无效选择器字符串在内部编译为从不匹配任何节点(而不是死机)的匹配器实现。例如,doc.Find(“~”)返回一个空的*选择对象。
// 2016-02-02:添加与DOM的NodeName属性类似的NodeName实用程序函数。它返回选择中第一个元素的标记名,以及非元素节点的其他相关值(有关详细信息,请参见文档)。添加类似于DOM的OuterHtml属性的OuterHtml实用程序函数(用小写字母命名为OuterHtml,以与选择项上的现有Html方法保持一致)。
// 2015-04-20:添加attor helper方法以返回属性值或默认值(如果不存在)。多亏了piotrkowalczuk。
// 2015-02-04:添加更多操纵功能-前置*-再次感谢安德鲁·斯通。
// 2014年11月28日:再次感谢安德鲁·斯通,增加了更多的操纵功能——替换*、包裹*和展开。
// 2014-11-07:添加操作函数(感谢Andrew Stone)和*Matcher函数,它们接收已编译的cascadia选择器而不是选择器字符串,从而避免goquery通过cascadia.MustCompile调用引发的潜在恐慌。这会带来更好的性能(选择器可以编译一次并重用)和更惯用的错误处理(您可以处理cascadia的编译错误,而不是从长期困扰我的恐慌中恢复过来)。请注意,预期的实际类型是由cascadia.Selector实现的Matcher接口。可以使用其他匹配器实现。
// 2014-11-06:将net/html的导入路径更改为golang.org/x/net/html(参见https://groups.google.com/forum/#!topic/golang nuts/eD8dh3T9yyA)。使用html.Nodes调用goquery时,请确保更新代码以使用新的导入路径。
// v0.3.2:添加NewDocumentFromReader()(感谢jweir),它允许从io.Reader创建goquery文档。
// v0.3.1:添加NewDocumentFromResponse()(感谢GJ),它允许从http响应创建goquery文档。
// v0.3.0:添加EachWithBreak(),它允许通过返回false来中断Each()循环。添加此函数,而不是更改现有的Each(),以避免破坏兼容性。
// v0.2.1:现在go.net/html是Go1.0兼容的(感谢@matrixik指出这一点),让go变得可获取。
// v0.2.0:在Slice()中添加对负索引的支持。断开更改文档。根被删除,文档本身就是一个选择(一个选择,根元素,就像Document.Root以前一样)。添加jQuery的最近()方法。
// v0.1.1:添加基准以用作重构的基线,重构Next…()和Prev…()方法以使用新html包的链表功能(Next/PrevSibling,FirstChild)。良好的性能提升(在某些情况下为40%)。
// v0.1.0:初始释放。


API
// goquery公开了两个结构,文档和选择,以及Matcher接口。与jQuery不同,jQuery作为DOM文档的一部分加载,从而作用于其包含的文档,而goquery不知道作用于哪个HTML文档。所以它需要被告知,这就是文档类型的用途。它保存根文档节点作为要操作的初始选择值。
// 对于同一个函数,jQuery通常有许多变体(无参数、选择器字符串参数、jQuery对象参数、DOM元素参数等等)。在goquery中,使用静态类型的签名,而不是将相同的功能作为具有可变空接口参数的单个方法公开,而是遵循以下命名约定:
// 当可以在没有参数的情况下调用jQuery等价物时,对于没有参数的签名(例如:Prev()),它与jQuery同名,而带有选择器字符串参数的版本称为XxxFiltered()(例如:PrevFiltered())
// 当jQuery等效项需要一个参数时,选择器字符串版本将使用与jQuery相同的名称(例如:is()
// 接受jQuery对象作为参数的签名在goquery中定义为XxxSelection(),并将*选择对象作为参数(例如:FilterSelection())
// 接受DOM元素作为jQuery参数的签名在goquery中定义为XxxNodes(),并采用*html.Node类型的可变参数(例如:FilterNodes())
// 在jQuery中接受函数作为参数的签名在goquery中定义为XxxFunction(),并将函数作为参数(例如:FilterFunction())
// 可以使用选择器字符串调用的goquery方法具有采用Matcher接口的相应版本,并定义为XxxMatcher()(例如:IsMatcher())
// 不在jQuery中但在Go中有用的实用程序函数被实现为函数(将*Selection作为参数),以避免*Selection的方法上潜在的命名冲突(保留用于jQuery等效行为)。
// 完整的软件包参考文档可在此处找到。
// 请注意,Cascadia的选择器不一定与jQuery(Sizzle)支持的所有选择器都匹配。有关详细信息,请参见cascadia项目。无效的选择器字符串编译为无法匹配任何节点的匹配器。将选择器字符串作为参数的各种函数的行为就是根据这一事实得出的,例如,(~是无效的选择器字符串):
// Find(“~”)返回一个空选择,因为选择器字符串与任何内容都不匹配。
// Add(“~”)返回一个新的选择,该选择包含与原始选择相同的节点,因为它没有添加任何节点(选择器字符串与任何内容都不匹配)。
// ParentsFiltered(~)返回一个空选择,因为选择器字符串与任何内容都不匹配。
// ParentsUntil(“~”)返回所选内容的所有父项,因为选择器字符串与要在顶部元素之前停止的任何元素都不匹配。

// 例子
// 在wiki中查看一些提示和技巧。
// 改编自示例_test.go:

package main

import (
  "fmt"
  "log"
  "net/http"

  "github.com/PuerkitoBio/goquery"
)

func ExampleScrape() {
  // Request the HTML page.
  res, err := http.Get("http://metalsucks.net")
  if err != nil {
    log.Fatal(err)
  }
  defer res.Body.Close()
  if res.StatusCode != 200 {
    log.Fatalf("status code error: %d %s", res.StatusCode, res.Status)
  }

  // Load the HTML document
  doc, err := goquery.NewDocumentFromReader(res.Body)
  if err != nil {
    log.Fatal(err)
  }

  // Find the review items
  doc.Find(".left-content article .post-title").Each(func(i int, s *goquery.Selection) {
		// For each item found, get the title
		title := s.Find("a").Text()
		fmt.Printf("Review %d: %s\n", i, title)
	})
}

func main() {
  ExampleScrape()
}

// 相关项目
// Goq,一个基于goquery和struct标记的HTML反序列化和刮取库。
// andybalholm/cascadia,goquery使用的CSS选择器库。
// suntong/cascadia,cascadia CSS选择器库的命令行接口,用于测试选择器。
// gocolly/colly,一个闪电般快速而优雅的刮片框架
// gnulnx/goperf,一个网站性能测试工具,也可以获取静态资产。
// MontFerret/ferret,声明性web抓取。
// tacusci/berrycms,一种现代的简单易用的CMS,具有易于编写的插件
// 数据流工具包,用于地鼠的网络抓取框架。
// Geziyor,一个用于Go的快速web爬行和抓取框架。支持JS渲染。
// Pagser,一个简单、简单、可扩展、可配置的HTML结构分析器,基于goquery和struct标记。
// Stitchrd,一个用于服务器端的服务器,包括使用css选择器和DOM更新。
// 支持
// 您可以通过多种方式支持该项目:

// 使用它,成为明星,用它建造一些东西,传播信息!
// 如果您确实构建了开放源代码或其他公开可见的内容,请告诉我,以便我可以将其添加到相关项目部分!
// 提出问题以改进项目(注意:文件打字和澄清也是问题!)
// 请在打开新问题之前搜索现有问题-它可能已被解决。
// 拉请求:请先讨论问题中的新代码,除非修复非常简单。
// 确保测试了新代码。
// 请注意现有的代码-破坏现有代码的PRs很有可能被拒绝,除非它修复了一个严重的问题。
// 赞助开发商
// 请参见Github上回购协议顶部的Github赞助商按钮
// 或者通过下面的BuyMeACoffee.com
// 给我买杯咖啡

// 许可证
// BSD 3条款许可证,与Go语言相同。卡斯卡迪亚的执照在这里。

// 文档
// 概述
// PackageGoQuery实现了类似于jQuery的功能,包括可链接语法,用于操作和查询HTML文档。
// 它为Go语言带来了类似于jQuery的语法和一组特性。它基于Go的net/html包和CSS选择器库cascadia。由于net/html解析器返回节点,而不是功能齐全的DOM树,因此jQuery的有状态操作函数(如height()、css()、detach())已被取消。
// 另外,由于net/html解析器需要UTF-8编码,goquery也需要UTF-8编码:调用者有责任确保源文档提供UTF-8编码的html。有关如何执行此操作的各种选项,请参见存储库的wiki。
// 在语法方面,它尽可能接近jQuery,尽可能使用相同的方法名,以及温暖和模糊的可链接接口。jQuery是一个非常流行的库,编写一个类似的HTML操作库最好遵循它的API,而不是重新开始(与Go的fmt包的精神相同),尽管它的一些方法不够直观(看看你,index()…)。
// 它与README.md文件中的其他文档一起托管在GitHub上:https://github.com/puerkitobio/goquery
// 请注意,由于net/html依赖关系,goquery需要Go1.1+。
// 根据行为的类别将各种方法拆分为文件。三个点(…)表示各种“重载”可用。

// *array.go:选择的类似数组的位置操作。
- Eq()
- First()
- Get()
- Index...()
- Last()
- Slice()

// *expand.go:扩展或扩充选择集的方法。
- Add...()
- AndSelf()
- Union(), which is an alias for AddSelection()

// *filter.go:减少选择集的筛选方法。
- End()
- Filter...()
- Has...()
- Intersection(), which is an alias of FilterSelection()
- Not...()

// *iteration.go:循环选择的节点的方法。
- Each()
- EachWithBreak()
- Map()

// *manipulation.go:修改文档的方法
- After...()
- Append...()
- Before...()
- Clone()
- Empty()
- Prepend...()
- Remove...()
- ReplaceWith...()
- Unwrap()
- Wrap...()
- WrapAll...()
- WrapInner...()

// *property.go:检查和获取节点属性值的方法。
- Attr*(), RemoveAttr(), SetAttr()
- AddClass(), HasClass(), RemoveClass(), ToggleClass()
- Html()
- Length()
- Size(), which is an alias for Length()
- Text()

// *query.go:查询或反映节点标识的方法。
- Contains()
- Is...()

// * traversal.go:遍历HTML文档树的方法。
- Children...()
- Contents()
- Find...()
- Next...()
- Parent[s]...()
- Prev...()
- Siblings...()

// *type.go:goquery公开的类型的定义。
- Document
- Selection
- Matcher

// *utilities.go:辅助函数(而不是*选择上的方法)的定义,这些函数不是jQuery的一部分,但对goquery很有用。
- NodeName
- OuterHtml


// 此示例将删除metalsucks.net主页上显示的评论。
package main

import (
	"fmt"
	"log"
	"net/http"

	"github.com/PuerkitoBio/goquery"
)

func main() {
	// Request the HTML page.
	res, err := http.Get("http://metalsucks.net")
	if err != nil {
		log.Fatal(err)
	}
	defer res.Body.Close()
	if res.StatusCode != 200 {
		log.Fatalf("status code error: %d %s", res.StatusCode, res.Status)
	}

	// Load the HTML document
	doc, err := goquery.NewDocumentFromReader(res.Body)
	if err != nil {
		log.Fatal(err)
	}

	// Find the review items
	doc.Find(".sidebar-reviews article .content-block").Each(func(i int, s *goquery.Selection) {
		// For each item found, get the band and title
		band := s.Find("a").Text()
		title := s.Find("i").Text()
		fmt.Printf("Review %d: %s - %s\n", i, band, title)
	})
	// To see the output of the Example while running the test suite (go test), simply
	// remove the leading "x" before Output on the next line. This will cause the
	// example to fail (all the "real" tests should pass).

	// xOutput: voluntarily fail the Example output.
}



Index
Constants
func NodeName(s *Selection) string
func OuterHtml(s *Selection) (string, error)
func Render(w io.Writer, s *Selection) error
type Document
func CloneDocument(doc *Document) *Document
func NewDocument(url string) (*Document, error)DEPRECATED
func NewDocumentFromNode(root *html.Node) *Document
func NewDocumentFromReader(r io.Reader) (*Document, error)
func NewDocumentFromResponse(res *http.Response) (*Document, error)DEPRECATED
type Matcher
func Single(selector string) Matcher
func SingleMatcher(m Matcher) Matcher
type Selection
func (s *Selection) Add(selector string) *Selection
func (s *Selection) AddBack() *Selection
func (s *Selection) AddBackFiltered(selector string) *Selection
func (s *Selection) AddBackMatcher(m Matcher) *Selection
func (s *Selection) AddClass(class ...string) *Selection
func (s *Selection) AddMatcher(m Matcher) *Selection
func (s *Selection) AddNodes(nodes ...*html.Node) *Selection
func (s *Selection) AddSelection(sel *Selection) *Selection
func (s *Selection) After(selector string) *Selection
func (s *Selection) AfterHtml(htmlStr string) *Selection
func (s *Selection) AfterMatcher(m Matcher) *Selection
func (s *Selection) AfterNodes(ns ...*html.Node) *Selection
func (s *Selection) AfterSelection(sel *Selection) *Selection
func (s *Selection) AndSelf() *SelectionDEPRECATED
func (s *Selection) Append(selector string) *Selection
func (s *Selection) AppendHtml(htmlStr string) *Selection
func (s *Selection) AppendMatcher(m Matcher) *Selection
func (s *Selection) AppendNodes(ns ...*html.Node) *Selection
func (s *Selection) AppendSelection(sel *Selection) *Selection
func (s *Selection) Attr(attrName string) (val string, exists bool)
func (s *Selection) AttrOr(attrName, defaultValue string) string
func (s *Selection) Before(selector string) *Selection
func (s *Selection) BeforeHtml(htmlStr string) *Selection
func (s *Selection) BeforeMatcher(m Matcher) *Selection
func (s *Selection) BeforeNodes(ns ...*html.Node) *Selection
func (s *Selection) BeforeSelection(sel *Selection) *Selection
func (s *Selection) Children() *Selection
func (s *Selection) ChildrenFiltered(selector string) *Selection
func (s *Selection) ChildrenMatcher(m Matcher) *Selection
func (s *Selection) Clone() *Selection
func (s *Selection) Closest(selector string) *Selection
func (s *Selection) ClosestMatcher(m Matcher) *Selection
func (s *Selection) ClosestNodes(nodes ...*html.Node) *Selection
func (s *Selection) ClosestSelection(sel *Selection) *Selection
func (s *Selection) Contains(n *html.Node) bool
func (s *Selection) Contents() *Selection
func (s *Selection) ContentsFiltered(selector string) *Selection
func (s *Selection) ContentsMatcher(m Matcher) *Selection
func (s *Selection) Each(f func(int, *Selection)) *Selection
func (s *Selection) EachWithBreak(f func(int, *Selection) bool) *Selection
func (s *Selection) Empty() *Selection
func (s *Selection) End() *Selection
func (s *Selection) Eq(index int) *Selection
func (s *Selection) Filter(selector string) *Selection
func (s *Selection) FilterFunction(f func(int, *Selection) bool) *Selection
func (s *Selection) FilterMatcher(m Matcher) *Selection
func (s *Selection) FilterNodes(nodes ...*html.Node) *Selection
func (s *Selection) FilterSelection(sel *Selection) *Selection
func (s *Selection) Find(selector string) *Selection
func (s *Selection) FindMatcher(m Matcher) *Selection
func (s *Selection) FindNodes(nodes ...*html.Node) *Selection
func (s *Selection) FindSelection(sel *Selection) *Selection
func (s *Selection) First() *Selection
func (s *Selection) Get(index int) *html.Node
func (s *Selection) Has(selector string) *Selection
func (s *Selection) HasClass(class string) bool
func (s *Selection) HasMatcher(m Matcher) *Selection
func (s *Selection) HasNodes(nodes ...*html.Node) *Selection
func (s *Selection) HasSelection(sel *Selection) *Selection
func (s *Selection) Html() (ret string, e error)
func (s *Selection) Index() int
func (s *Selection) IndexMatcher(m Matcher) int
func (s *Selection) IndexOfNode(node *html.Node) int
func (s *Selection) IndexOfSelection(sel *Selection) int
func (s *Selection) IndexSelector(selector string) int
func (s *Selection) Intersection(sel *Selection) *Selection
func (s *Selection) Is(selector string) bool
func (s *Selection) IsFunction(f func(int, *Selection) bool) bool
func (s *Selection) IsMatcher(m Matcher) bool
func (s *Selection) IsNodes(nodes ...*html.Node) bool
func (s *Selection) IsSelection(sel *Selection) bool
func (s *Selection) Last() *Selection
func (s *Selection) Length() int
func (s *Selection) Map(f func(int, *Selection) string) (result []string)
func (s *Selection) Next() *Selection
func (s *Selection) NextAll() *Selection
func (s *Selection) NextAllFiltered(selector string) *Selection
func (s *Selection) NextAllMatcher(m Matcher) *Selection
func (s *Selection) NextFiltered(selector string) *Selection
func (s *Selection) NextFilteredUntil(filterSelector, untilSelector string) *Selection
func (s *Selection) NextFilteredUntilMatcher(filter, until Matcher) *Selection
func (s *Selection) NextFilteredUntilNodes(filterSelector string, nodes ...*html.Node) *Selection
func (s *Selection) NextFilteredUntilSelection(filterSelector string, sel *Selection) *Selection
func (s *Selection) NextMatcher(m Matcher) *Selection
func (s *Selection) NextMatcherUntilNodes(filter Matcher, nodes ...*html.Node) *Selection
func (s *Selection) NextMatcherUntilSelection(filter Matcher, sel *Selection) *Selection
func (s *Selection) NextUntil(selector string) *Selection
func (s *Selection) NextUntilMatcher(m Matcher) *Selection
func (s *Selection) NextUntilNodes(nodes ...*html.Node) *Selection
func (s *Selection) NextUntilSelection(sel *Selection) *Selection
func (s *Selection) Not(selector string) *Selection
func (s *Selection) NotFunction(f func(int, *Selection) bool) *Selection
func (s *Selection) NotMatcher(m Matcher) *Selection
func (s *Selection) NotNodes(nodes ...*html.Node) *Selection
func (s *Selection) NotSelection(sel *Selection) *Selection
func (s *Selection) Parent() *Selection
func (s *Selection) ParentFiltered(selector string) *Selection
func (s *Selection) ParentMatcher(m Matcher) *Selection
func (s *Selection) Parents() *Selection
func (s *Selection) ParentsFiltered(selector string) *Selection
func (s *Selection) ParentsFilteredUntil(filterSelector, untilSelector string) *Selection
func (s *Selection) ParentsFilteredUntilMatcher(filter, until Matcher) *Selection
func (s *Selection) ParentsFilteredUntilNodes(filterSelector string, nodes ...*html.Node) *Selection
func (s *Selection) ParentsFilteredUntilSelection(filterSelector string, sel *Selection) *Selection
func (s *Selection) ParentsMatcher(m Matcher) *Selection
func (s *Selection) ParentsMatcherUntilNodes(filter Matcher, nodes ...*html.Node) *Selection
func (s *Selection) ParentsMatcherUntilSelection(filter Matcher, sel *Selection) *Selection
func (s *Selection) ParentsUntil(selector string) *Selection
func (s *Selection) ParentsUntilMatcher(m Matcher) *Selection
func (s *Selection) ParentsUntilNodes(nodes ...*html.Node) *Selection
func (s *Selection) ParentsUntilSelection(sel *Selection) *Selection
func (s *Selection) Prepend(selector string) *Selection
func (s *Selection) PrependHtml(htmlStr string) *Selection
func (s *Selection) PrependMatcher(m Matcher) *Selection
func (s *Selection) PrependNodes(ns ...*html.Node) *Selection
func (s *Selection) PrependSelection(sel *Selection) *Selection
func (s *Selection) Prev() *Selection
func (s *Selection) PrevAll() *Selection
func (s *Selection) PrevAllFiltered(selector string) *Selection
func (s *Selection) PrevAllMatcher(m Matcher) *Selection
func (s *Selection) PrevFiltered(selector string) *Selection
func (s *Selection) PrevFilteredUntil(filterSelector, untilSelector string) *Selection
func (s *Selection) PrevFilteredUntilMatcher(filter, until Matcher) *Selection
func (s *Selection) PrevFilteredUntilNodes(filterSelector string, nodes ...*html.Node) *Selection
func (s *Selection) PrevFilteredUntilSelection(filterSelector string, sel *Selection) *Selection
func (s *Selection) PrevMatcher(m Matcher) *Selection
func (s *Selection) PrevMatcherUntilNodes(filter Matcher, nodes ...*html.Node) *Selection
func (s *Selection) PrevMatcherUntilSelection(filter Matcher, sel *Selection) *Selection
func (s *Selection) PrevUntil(selector string) *Selection
func (s *Selection) PrevUntilMatcher(m Matcher) *Selection
func (s *Selection) PrevUntilNodes(nodes ...*html.Node) *Selection
func (s *Selection) PrevUntilSelection(sel *Selection) *Selection
func (s *Selection) Remove() *Selection
func (s *Selection) RemoveAttr(attrName string) *Selection
func (s *Selection) RemoveClass(class ...string) *Selection
func (s *Selection) RemoveFiltered(selector string) *Selection
func (s *Selection) RemoveMatcher(m Matcher) *Selection
func (s *Selection) ReplaceWith(selector string) *Selection
func (s *Selection) ReplaceWithHtml(htmlStr string) *Selection
func (s *Selection) ReplaceWithMatcher(m Matcher) *Selection
func (s *Selection) ReplaceWithNodes(ns ...*html.Node) *Selection
func (s *Selection) ReplaceWithSelection(sel *Selection) *Selection
func (s *Selection) SetAttr(attrName, val string) *Selection
func (s *Selection) SetHtml(htmlStr string) *Selection
func (s *Selection) SetText(text string) *Selection
func (s *Selection) Siblings() *Selection
func (s *Selection) SiblingsFiltered(selector string) *Selection
func (s *Selection) SiblingsMatcher(m Matcher) *Selection
func (s *Selection) Size() int
func (s *Selection) Slice(start, end int) *Selection
func (s *Selection) Text() string
func (s *Selection) ToggleClass(class ...string) *Selection
func (s *Selection) Union(sel *Selection) *Selection
func (s *Selection) Unwrap() *Selection
func (s *Selection) Wrap(selector string) *Selection
func (s *Selection) WrapAll(selector string) *Selection
func (s *Selection) WrapAllHtml(htmlStr string) *Selection
func (s *Selection) WrapAllMatcher(m Matcher) *Selection
func (s *Selection) WrapAllNode(n *html.Node) *Selection
func (s *Selection) WrapAllSelection(sel *Selection) *Selection
func (s *Selection) WrapHtml(htmlStr string) *Selection
func (s *Selection) WrapInner(selector string) *Selection
func (s *Selection) WrapInnerHtml(htmlStr string) *Selection
func (s *Selection) WrapInnerMatcher(m Matcher) *Selection
func (s *Selection) WrapInnerNode(n *html.Node) *Selection
func (s *Selection) WrapInnerSelection(sel *Selection) *Selection
func (s *Selection) WrapMatcher(m Matcher) *Selection
func (s *Selection) WrapNode(n *html.Node) *Selection
func (s *Selection) WrapSelection(sel *Selection) *Selection

// 例子
Package
NewDocumentFromReader (File)
NewDocumentFromReader (String)
Single

Constants
const (
// //ToEnd是一个特殊的索引值,可以在调用中用作结束索引
// //进行切片以选择所有图元,直到选择结束。
// //它相当于传递(*Selection).Length()。
ToEnd=maxInt
)


Functions
func NodeName 
func NodeName(s *Selection) string
// NodeName返回所选内容中第一个元素的节点名。它试图以与DOM的nodeName属性类似的方式进行操作(https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeName).

// Go的net/html包定义了以下节点类型,列出了该函数的相应返回值:
ErrorNode : #error
TextNode : #text
DocumentNode : #document
ElementNode : the element's tag name
CommentNode : #comment
DoctypeNode : the name of the document type

func OuterHtml 
func OuterHtml(s *Selection) (string, error)
// OuterHtml返回选择中第一项的外部HTML呈现,即包含第一个元素的标记和属性的HTML。

// 与InnerHtml不同,这是一个函数,而不是选择的方法,因为这不是jQuery方法(在javascript领域,这是DOM提供的属性)。

func Render 
func Render(w io.Writer, s *Selection) error
// Render从选择器中呈现第一个元素的html并将其写入编写器。它的行为与OuterHtml相同,但写入w而不是返回字符串。

// 类型
type Document 
type Document struct {
	*Selection
	Url *url.URL
// //包含已过滤或未报告的字段
}
// 文档表示要操作的HTML文档。与jQuery不同,jQuery作为DOM文档的一部分加载,从而作用于其包含的文档,而GoQuery不知道作用于哪个HTML文档。所以它需要被告知,这就是Document类的用途。它保存要操作的根文档节点,并可以在此文档上进行选择。

func CloneDocument 
func CloneDocument(doc *Document) *Document
// CloneDocument创建文档的深度克隆。


func NewDocumentFromNode 
func NewDocumentFromNode(root *html.Node) *Document
// NewDocumentFromNode是一个以根html节点为参数的文档构造函数。

func NewDocumentFromReader 
func NewDocumentFromReader(r io.Reader) (*Document, error)
// NewDocumentFromReader从io.Reader返回文档。如果读卡器的数据不能解析为html,它将返回一个错误作为第二个值。它不会检查读卡器是否也是io。Closer,提供的读卡器从未被此调用关闭。如果需要,呼叫方有责任关闭它。

// 示例(文件)
// 此示例演示如何从文件中使用NewDocumentFromReader。
package main

import (
	"log"
	"os"

	"github.com/PuerkitoBio/goquery"
)

func main() {
	// create from a file
	f, err := os.Open("some/file.html")
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()
	doc, err := goquery.NewDocumentFromReader(f)
	if err != nil {
		log.Fatal(err)
	}
	// use the goquery document...
	_ = doc.Find("h1")
}



// 示例(字符串)
// 此示例演示如何从字符串使用NewDocumentFromReader。
package main

import (
	"fmt"
	"log"
	"strings"

	"github.com/PuerkitoBio/goquery"
)

func main() {
	// create from a string
	data := `
<html>
	<head>
		<title>My document</title>
	</head>
	<body>
		<h1>Header</h1>
	</body>
</html>`

	doc, err := goquery.NewDocumentFromReader(strings.NewReader(data))
	if err != nil {
		log.Fatal(err)
	}
	header := doc.Find("h1").Text()
	fmt.Println(header)

}



func NewDocumentFromResponse

type Matcher 
type Matcher interface {
type Matcher interface {
	Match(*html.Node) bool
	MatchAll(*html.Node) []*html.Node
	Filter([]*html.Node) []*html.Node
}
// Matcher是一个接口,它定义了将HTML节点与编译的选择器字符串相匹配的方法。Cascadia的选择器实现了这个接口。

func Single 
func Single(selector string) Matcher
// Single将选择器字符串编译为匹配器,该匹配器在找到第一个匹配后停止。
// 默认情况下,Selection.Find和其他接受选择器字符串来选择节点的函数将使用与该选择器对应的所有匹配项。通过使用Single返回的Matcher,最多会选择第一个匹配项。
// 例如,这两个语句在语义上是等价的:
sel1 := doc.Find("a").First()
sel2 := doc.FindMatcher(goquery.Single("a"))
// 使用Single的一个经过优化,在大型文档上可能更快。

// 与标准匹配器相比,只有Matcher接口的matchell方法的行为发生了改变。这意味着Matcher的single selection属性仅适用于Matcher用于选择节点的选择方法,而不是过滤或检查节点是否与Matcher匹配-在这些情况下,Matcher的行为保持不变(例如FilterMatcher(single(“div”))仍将导致具有多个“div”的选择(如果选择中有许多“div”开头)。

// 实例
package main

import (
	"fmt"
	"log"
	"strings"

	"github.com/PuerkitoBio/goquery"
)

func main() {
	html := `
<html>
  <body>
    <div>1</div>
    <div>2</div>
    <div>3</div>
  </body>
</html>
`
	doc, err := goquery.NewDocumentFromReader(strings.NewReader(html))
	if err != nil {
		log.Fatal(err)
	}

	// By default, the selector string selects all matching nodes
	multiSel := doc.Find("div")
	fmt.Println(multiSel.Text())

	// Using goquery.Single, only the first match is selected
	singleSel := doc.FindMatcher(goquery.Single("div"))
	fmt.Println(singleSel.Text())

}


// 输出:
// 123
// 1.

// 共有
// 总体安排
// 跑
func SingleMatcher 
func SingleMatcher(m Matcher) Matcher
// SingleMatcher返回匹配与m相同节点的匹配器,但在找到第一个匹配后停止。

// 有关更多详细信息,请参阅单功能的文档。

type Selection 
type Selection struct {
    Nodes[]*html.Node
    //包含已过滤或未报告的字段
}
// 选择表示符合某些条件的节点集合。可以使用Document.Find创建初始选择,然后使用类似jQuery的可链接语法和方法进行操作。

func (*Selection) Add 
func (s *Selection) Add(selector string) *Selection
// 添加将选择器字符串的匹配节点添加到当前选择中的节点,并返回新的选择对象。选择器字符串在当前选择对象的文档上下文中运行。

func (*Selection) AddBack 
func (s *Selection) AddBack() *Selection
// AddBack将堆栈上的前一组元素添加到当前集合。它返回一个新的选择对象,其中包含当前选择与上一个选择的组合。

func (*Selection) AddBackFiltered 
func (s *Selection) AddBackFiltered(selector string) *Selection
// AddBackfilted将堆栈上的前一组元素减少为与选择器字符串匹配的元素,并将它们添加到当前集合中。它返回一个新的选择对象,其中包含当前选择与过滤后的上一个选择的组合

func (*Selection) AddBackMatcher 
func (s *Selection) AddBackMatcher(m Matcher) *Selection
// AddBackMatcher将堆栈上以前的元素集减少为与mateher匹配的元素集,并将它们添加到curernt集中。它返回一个新的选择对象,其中包含当前选择与过滤后的上一个选择的组合

func (*Selection) AddClass 
func (s *Selection) AddClass(class ...string) *Selection
// AddClass将给定的类添加到匹配元素集中的每个元素。可以指定多个类名,用空格分隔或通过多个参数分隔。

func (*Selection) AddMatcher 
func (s *Selection) AddMatcher(m Matcher) *Selection
// AddMatcher将匹配器的匹配节点添加到当前选择中的节点,并返回一个新的选择对象。匹配器在当前选择对象的文档上下文中运行。

func (*Selection) AddNodes 
func (s *Selection) AddNodes(nodes ...*html.Node) *Selection
// AddNodes将指定的节点添加到当前选择中的节点,并返回新的选择对象。

func (*Selection) AddSelection 
func (s *Selection) AddSelection(sel *Selection) *Selection
// AddSelection将指定选择对象的节点添加到当前选择中的节点,并返回新的选择对象。

func (*Selection) After 
func (s *Selection) After(selector string) *Selection
// After应用根文档中的选择器,并在匹配元素集中的元素之后插入匹配元素。
// 如果选择中的一个匹配元素当前不在文档中,则无法在其后面插入节点,因此将忽略它。
// 这遵循与Selection.Append相同的规则。

func (*Selection) AfterHtml 
func (s *Selection) AfterHtml(htmlStr string) *Selection
// AfterHtml解析html并将其插入匹配元素集之后。
// 这遵循与Selection.Append相同的规则。

func (*Selection) AfterMatcher 
func (s *Selection) AfterMatcher(m Matcher) *Selection
// AfterMatcher应用根文档中的匹配器,并在匹配元素集中的元素之后插入匹配元素。
// 如果选择中的一个匹配元素当前不在文档中,则无法在其后面插入节点,因此将忽略它。
// 这遵循与Selection.Append相同的规则。

func (*Selection) AfterNodes 
func (s *Selection) AfterNodes(ns ...*html.Node) *Selection
// AfterNodes在匹配元素集中的每个元素之后插入节点。
// 这遵循与Selection.Append相同的规则。

func (*Selection) AfterSelection 
func (s *Selection) AfterSelection(sel *Selection) *Selection
// AfterSelection在匹配元素集中的每个元素之后插入选择中的元素。
// 这遵循与Selection.Append相同的规则。

func (*Selection) Append 
func (s *Selection) Append(selector string) *Selection
// Append将选择器指定的元素追加到匹配元素集中每个元素的末尾,遵循以下规则:
// 1) 选择器将应用于根文档。
// 2) 作为文档一部分的元素将移动到新位置。
// 3) 如果要附加到多个位置,则克隆节点将附加到除最后一个位置之外的所有目标位置,最后一个位置将按照(2)中的说明移动。

func (*Selection) AppendHtml 
func (s *Selection) AppendHtml(htmlStr string) *Selection
// AppendHtml解析html并将其附加到匹配元素集。

func (*Selection) AppendMatcher 
func (s *Selection) AppendMatcher(m Matcher) *Selection
// AppendMatcher将匹配器指定的元素追加到匹配元素集中每个元素的末尾。
// 这遵循与Selection.Append相同的规则。

func (*Selection) AppendNodes 
func (s *Selection) AppendNodes(ns ...*html.Node) *Selection
// AppendNodes将指定的节点追加到匹配元素集中的每个节点。
// 这遵循与Selection.Append相同的规则。

func (*Selection) AppendSelection 
func (s *Selection) AppendSelection(sel *Selection) *Selection
// AppendSelection将选择中的元素追加到匹配元素集中每个元素的末尾。
// 这遵循与Selection.Append相同的规则。

func (*Selection) Attr 
func (s *Selection) Attr(attrName string) (val string, exists bool)
// Attr为选择中的第一个元素获取指定属性的值。要单独获取每个元素的值,请使用循环构造,例如each或Map方法。

func (*Selection) AttrOr 
func (s *Selection) AttrOr(attrName, defaultValue string) string
// attor的工作方式类似于Attr,但若属性不存在,则返回默认值。

func (*Selection) Before 
func (s *Selection) Before(selector string) *Selection
// Before在匹配元素集中的每个元素之前插入匹配元素。
// 这遵循与Selection.Append相同的规则。

func (*Selection) BeforeHtml 
func (s *Selection) BeforeHtml(htmlStr string) *Selection
// BeforeHtml解析html并将其插入匹配元素集之前。
// 这遵循与Selection.Append相同的规则。

func (*Selection) BeforeMatcher 
func (s *Selection) BeforeMatcher(m Matcher) *Selection
// BeforeMatcher在匹配元素集中的每个元素之前插入匹配元素。
// 这遵循与Selection.Append相同的规则。

func (*Selection) BeforeNodes 
func (s *Selection) BeforeNodes(ns ...*html.Node) *Selection
// BeforeNodes在匹配元素集中的每个元素之前插入节点。
// 这遵循与Selection.Append相同的规则。

func (*Selection) BeforeSelection 
func (s *Selection) BeforeSelection(sel *Selection) *Selection
// BeforeSelection在匹配元素集中的每个元素之前插入选择中的元素。
// 这遵循与Selection.Append相同的规则。

func (*Selection) Children 
func (s *Selection) Children() *Selection
// Children获取选择中每个元素的子元素。它返回一个包含这些元素的新选择对象。

func (*Selection) ChildrenFiltered 
func (s *Selection) ChildrenFiltered(selector string) *Selection
// ChildrenFiltered获取所选内容中每个元素的子元素,由指定的选择器进行筛选。它返回一个包含这些元素的新选择对象。

func (*Selection) ChildrenMatcher 
func (s *Selection) ChildrenMatcher(m Matcher) *Selection
// ChildrenMatcher获取选择中每个元素的子元素,并由指定的匹配器过滤。它返回一个包含这些元素的新选择对象。

func (*Selection) Clone 
func (s *Selection) Clone() *Selection
// 克隆创建匹配节点集的深度副本。新节点将不会附加到文档。

func (*Selection) Closest 
func (s *Selection) Closest(selector string) *Selection
// 通过测试元素本身并在DOM树中向上遍历其祖先,获取与选择器匹配的第一个元素。

func (*Selection) ClosestMatcher 
func (s *Selection) ClosestMatcher(m Matcher) *Selection
// ClosesMatcher通过测试元素本身并在DOM树中遍历它的祖先来获取与匹配器匹配的第一个元素。

func (*Selection) ClosestNodes 
func (s *Selection) ClosestNodes(nodes ...*html.Node) *Selection
// ClosestNodes通过测试元素本身并在DOM树中遍历其祖先,获取与其中一个节点匹配的第一个元素。

func (*Selection) ClosestSelection 
func (s *Selection) ClosestSelection(sel *Selection) *Selection
// ClosestSelection通过测试元素本身并在DOM树中遍历其祖先,获取与选择中的一个节点匹配的第一个元素。

func (*Selection) Contains 
func (s *Selection) Contains(n *html.Node) bool
// 如果指定节点位于选择对象中某个节点的任意深度内,Contains返回true。它不具有包容性,其行为类似于jQuery的实现,并且与Javascript的.contains不同,因此如果包含的节点本身在选择中,它将返回false。

func (*Selection) Contents 
func (s *Selection) Contents() *Selection
// 内容获取所选内容中每个元素的子元素,包括文本和注释节点。它返回一个包含这些元素的新选择对象。

func (*Selection) ContentsFiltered 
func (s *Selection) ContentsFiltered(selector string) *Selection
// ContentsFiltered获取所选内容中每个元素的子元素,这些子元素由指定的选择器过滤。它返回一个包含这些元素的新选择对象。由于选择器仅作用于元素节点,因此此函数是ChildrenFiltered的别名,除非选择器为空,在这种情况下,它是内容的别名。

func (*Selection) ContentsMatcher 
func (s *Selection) ContentsMatcher(m Matcher) *Selection
// ContentsMatcher获取所选内容中每个元素的子元素,并由指定的匹配器进行筛选。它返回一个包含这些元素的新选择对象。由于Matcher仅作用于元素节点,因此此函数是ChildrenMatcher的别名。

func (*Selection) Each 
func (s *Selection) Each(f func(int, *Selection)) *Selection
// 每个元素迭代一个选择对象,为每个匹配的元素执行一个函数。它返回当前选择对象。为选择中的每个元素调用函数f,该选择中元素的索引从0开始,并且一个*选择仅包含该元素。

func (*Selection) EachWithBreak 
func (s *Selection) EachWithBreak(f func(int, *Selection) bool) *Selection
// 每个WithBreak迭代一个选择对象,为每个匹配的元素执行一个函数。除了可以通过在回调函数中返回false来中断循环之外,它与每一个都相同。它返回当前选择对象。

func (*Selection) Empty 
func (s *Selection) Empty() *Selection
// Empty从匹配元素集中删除所有子节点。它返回新选择中的子节点。

func (*Selection) End 
func (s *Selection) End() *Selection
// End结束当前链中最近的筛选操作,并将匹配元素集返回到其以前的状态。

func (*Selection) Eq 
func (s *Selection) Eq(index int) *Selection
// Eq将匹配元素集减少到指定索引处的元素集。如果给定负索引,则从集合末尾开始向后计数。它返回一个新的选择对象,如果索引无效,则返回一个空的选择对象。

func (*Selection) Filter 
func (s *Selection) Filter(selector string) *Selection
// 筛选器将匹配的元素集减少为与选择器字符串匹配的元素集。它为匹配元素的子集返回一个新的选择对象。

func (*Selection) FilterFunction 
func (s *Selection) FilterFunction(f func(int, *Selection) bool) *Selection
// FilterFunction将匹配元素集减少为通过函数测试的元素集。它将为该元素子集返回一个新的选择对象。

func (*Selection) FilterMatcher 
func (s *Selection) FilterMatcher(m Matcher) *Selection
// FilterMatcher将匹配元素集减少为与给定匹配器匹配的元素集。它为匹配元素的子集返回一个新的选择对象。

func (*Selection) FilterNodes 
func (s *Selection) FilterNodes(nodes ...*html.Node) *Selection
// FilterNodes将匹配的元素集减少为与指定节点匹配的元素集。它将为该元素子集返回一个新的选择对象。

func (*Selection) FilterSelection 
func (s *Selection) FilterSelection(sel *Selection) *Selection
// FilterSelection将匹配的元素集减少为与指定选择对象中的节点匹配的元素集。它将为该元素子集返回一个新的选择对象。

func (*Selection) Find 
func (s *Selection) Find(selector string) *Selection
// Find获取当前匹配元素集中每个元素的后代,并通过选择器进行筛选。它返回一个包含这些匹配元素的新选择对象。

func (*Selection) FindMatcher 
func (s *Selection) FindMatcher(m Matcher) *Selection
// FindMatcher获取当前匹配元素集中每个元素的子元素,并由匹配器过滤。它返回一个包含这些匹配元素的新选择对象。

func (*Selection) FindNodes 
func (s *Selection) FindNodes(nodes ...*html.Node) *Selection
// FindNodes获取当前选择中每个元素的后代,这些后代由一些节点过滤。它返回一个包含这些匹配元素的新选择对象。

func (*Selection) FindSelection 
func (s *Selection) FindSelection(sel *Selection) *Selection
// FindSelection获取当前选择中每个元素的后代,并通过选择进行过滤。它返回一个包含这些匹配元素的新选择对象。

func (*Selection) First 
func (s *Selection) First() *Selection
// First将匹配元素集减少为集合中的第一个元素。它返回一个新的选择对象,如果选择为空,则返回一个空的选择对象。

func (*Selection) Get 
func (s *Selection) Get(index int) *html.Node
// Get检索指定索引处的基础节点。由于节点数组在选择对象上可用,因此未实现不带参数的Get。

func (*Selection) Has 
func (s *Selection) Has(selector string) *Selection
// 已将匹配的元素集减少为具有与选择器匹配的后代的元素集。它返回一个带有匹配元素的新选择对象。

func (*Selection) HasClass 
func (s *Selection) HasClass(class string) bool
// HasClass确定是否将任何匹配的元素分配给给定的类。

func (*Selection) HasMatcher 
func (s *Selection) HasMatcher(m Matcher) *Selection
// HasMatcher将匹配的元素集减少为具有与匹配器匹配的后代的元素集。它返回一个带有匹配元素的新选择对象。

func (*Selection) HasNodes 
func (s *Selection) HasNodes(nodes ...*html.Node) *Selection
// HasNodes将匹配的元素集减少为具有匹配其中一个节点的后代的元素集。它返回一个带有匹配元素的新选择对象。

func (*Selection) HasSelection 
func (s *Selection) HasSelection(sel *Selection) *Selection
// HasSelection将匹配的元素集减少为具有与指定选择对象的一个节点匹配的后代的元素集。它返回一个带有匹配元素的新选择对象。

func (*Selection) Html 
func (s *Selection) Html() (ret string, e error)
// Html获取匹配元素集中第一个元素的Html内容。它包括文本和注释节点。

func (*Selection) Index 
func (s *Selection) Index() int
// 索引返回选择对象中第一个元素相对于其同级元素的位置。

func (*Selection) IndexMatcher 
func (s *Selection) IndexMatcher(m Matcher) int
// IndexMatcher返回选择对象中第一个元素相对于匹配器匹配的元素的位置,如果未找到,则返回-1。

func (*Selection) IndexOfNode 
func (s *Selection) IndexOfNode(node *html.Node) int
// IndexOfNode返回选择对象中指定节点的位置,如果未找到,则返回-1。

func (*Selection) IndexOfSelection 
func (s *Selection) IndexOfSelection(sel *Selection) int
// IndexOfSelection返回此选择对象中指定选择对象中第一个节点的位置,如果未找到,则返回-1。

func (*Selection) IndexSelector 
func (s *Selection) IndexSelector(selector string) int
// IndexSelector返回选择对象中第一个元素相对于选择器匹配的元素的位置,如果未找到,则返回-1。

func (*Selection) Intersection 
func (s *Selection) Intersection(sel *Selection) *Selection
// 交叉点是FilterSelection的别名。

func (*Selection) Is 
func (s *Selection) Is(selector string) bool
// Is根据选择器检查当前匹配的元素集,如果这些元素中至少有一个匹配,则返回true。

func (*Selection) IsFunction 
func (s *Selection) IsFunction(f func(int, *Selection) bool) bool
// IsFunction根据谓词检查当前匹配的元素集,如果这些元素中至少有一个匹配,则返回true。

func (*Selection) IsMatcher 
func (s *Selection) IsMatcher(m Matcher) bool
// IsMatcher根据匹配器检查当前匹配的元素集,如果这些元素中至少有一个匹配,则返回true。

func (*Selection) IsNodes 
func (s *Selection) IsNodes(nodes ...*html.Node) bool
// IsNodes根据指定的节点检查当前匹配的元素集,如果这些元素中至少有一个匹配,则返回true。

func (*Selection) IsSelection 
func (s *Selection) IsSelection(sel *Selection) bool
// IsSelection根据选择对象检查当前匹配的元素集,如果其中至少有一个元素匹配,则返回true。

func (*Selection) Last 
func (s *Selection) Last() *Selection
// Last将匹配元素集减少到集合中的最后一个。它返回一个新的选择对象,如果选择为空,则返回一个空的选择对象。

func (*Selection) Length 
func (s *Selection) Length() int
// Length返回选择对象中的元素数。

func (*Selection) Map 
func (s *Selection) Map(f func(int, *Selection) string) (result []string)
// Map通过一个函数传递当前匹配集中的每个元素,生成一个包含返回值的字符串片段。为选择中的每个元素调用函数f,该选择中元素的索引从0开始,并且一个*选择仅包含该元素。

func (*Selection) Next 
func (s *Selection) Next() *Selection
// 下一步获取选择中每个元素紧跟其后的同级。它返回一个包含匹配元素的新选择对象。

func (*Selection) NextAll 
func (s *Selection) NextAll() *Selection
// NextAll获取选择中每个元素的以下所有同级。它返回一个包含匹配元素的新选择对象。

func (*Selection) NextAllFiltered 
func (s *Selection) NextAllFiltered(selector string) *Selection
// NextTallFiltered获取由选择器筛选的选择中每个元素的所有以下兄弟姐妹。它返回一个包含匹配元素的新选择对象。

func (*Selection) NextAllMatcher 
func (s *Selection) NextAllMatcher(m Matcher) *Selection
// NextAllMatcher获取由匹配器过滤的选择中每个元素的以下所有同级。它返回一个包含匹配元素的新选择对象。

func (*Selection) NextFiltered 
func (s *Selection) NextFiltered(selector string) *Selection
// NextFiltered获取选择器筛选的选择中每个元素的紧随其后的同级。它返回一个包含匹配元素的新选择对象。

func (*Selection) NextFilteredUntil 
func (s *Selection) NextFilteredUntil(filterSelector, untilSelector string) *Selection
// NextFilteredUntil类似于NextUntil,它具有基于选择器字符串过滤结果的选项。它返回一个包含匹配元素的新选择对象。

func (*Selection) NextFilteredUntilMatcher 
func (s *Selection) NextFilteredUntilMatcher(filter, until Matcher) *Selection
// NextFilteredUntilMatcher类似于NextUntilMatcher,它具有基于匹配器过滤结果的选项。它返回一个包含匹配元素的新选择对象。

func (*Selection) NextFilteredUntilNodes 
func (s *Selection) NextFilteredUntilNodes(filterSelector string, nodes ...*html.Node) *Selection
// NextFilteredUntilNodes类似于NextUntilNodes,具有基于选择器字符串过滤结果的选项。它返回一个包含匹配元素的新选择对象。

func (*Selection) NextFilteredUntilSelection 
func (s *Selection) NextFilteredUntilSelection(filterSelector string, sel *Selection) *Selection
// NextFilteredUntilSelection类似于NextUntilSelection,具有基于选择器字符串过滤结果的选项。它返回一个包含匹配元素的新选择对象。

func (*Selection) NextMatcher 
func (s *Selection) NextMatcher(m Matcher) *Selection
// NextMatcher获取由匹配器过滤的选择中每个元素的紧随其后的同级。它返回一个包含匹配元素的新选择对象。

func (*Selection) NextMatcherUntilNodes 
func (s *Selection) NextMatcherUntilNodes(filter Matcher, nodes ...*html.Node) *Selection
// NextMatcherUntilNodes与NextUntilNodes类似,具有基于匹配器过滤结果的选项。它返回一个包含匹配元素的新选择对象。

func (*Selection) NextMatcherUntilSelection 
func (s *Selection) NextMatcherUntilSelection(filter Matcher, sel *Selection) *Selection
// NextMatcherUntilSelection与NextUntilSelection类似,它具有基于匹配器过滤结果的选项。它返回一个包含匹配元素的新选择对象。

func (*Selection) NextUntil 
func (s *Selection) NextUntil(selector string) *Selection
// NextUntil获取每个元素的以下所有同级,直到但不包括选择器匹配的元素。它返回一个包含匹配元素的新选择对象。

func (*Selection) NextUntilMatcher 
func (s *Selection) NextUntilMatcher(m Matcher) *Selection
// NextUntilMatcher获取每个元素的以下所有同级,直到但不包括匹配器匹配的元素。它返回一个包含匹配元素的新选择对象。

func (*Selection) NextUntilNodes 
func (s *Selection) NextUntilNodes(nodes ...*html.Node) *Selection
// NextUntilNodes获取每个元素的以下所有同级,直到但不包括节点匹配的元素。它返回一个包含匹配元素的新选择对象。

func (*Selection) NextUntilSelection 
func (s *Selection) NextUntilSelection(sel *Selection) *Selection
// NextUntilSelection获取每个元素的以下所有同级,直到但不包括与该选择匹配的元素。它返回一个包含匹配元素的新选择对象。

func (*Selection) Not 
func (s *Selection) Not(selector string) *Selection
// Not从选择中删除与选择器字符串匹配的元素。它返回一个删除了匹配元素的新选择对象。

func (*Selection) NotFunction 
func (s *Selection) NotFunction(f func(int, *Selection) bool) *Selection
// NotFunction从选择中删除通过函数测试的元素。它返回一个删除了匹配元素的新选择对象。

func (*Selection) NotMatcher 
func (s *Selection) NotMatcher(m Matcher) *Selection
// NotMatcher从选择中删除与给定匹配器匹配的元素。它返回一个删除了匹配元素的新选择对象。

func (*Selection) NotNodes 
func (s *Selection) NotNodes(nodes ...*html.Node) *Selection
// NotNodes从选择中删除与指定节点匹配的元素。它返回一个删除了匹配元素的新选择对象。

func (*Selection) NotSelection 
func (s *Selection) NotSelection(sel *Selection) *Selection
// NotSelection从选择中删除与指定选择对象中的节点匹配的元素。它返回一个删除了匹配元素的新选择对象。

func (*Selection) Parent 
func (s *Selection) Parent() *Selection
// 父对象获取所选内容中每个元素的父对象。它返回一个包含匹配元素的新选择对象。

func (*Selection) ParentFiltered 
func (s *Selection) ParentFiltered(selector string) *Selection
// ParentFiltered获取选择器筛选的选择中每个元素的父元素。它返回一个包含匹配元素的新选择对象。

func (*Selection) ParentMatcher 
func (s *Selection) ParentMatcher(m Matcher) *Selection
// ParentMatcher获取由匹配器过滤的选择中每个元素的父元素。它返回一个包含匹配元素的新选择对象。

func (*Selection) Parents 
func (s *Selection) Parents() *Selection
// 父元素获取当前选择中每个元素的父元素。它返回一个包含匹配元素的新选择对象。

func (*Selection) ParentsFiltered 
func (s *Selection) ParentsFiltered(selector string) *Selection
// ParentsFiltered获取当前选择中每个元素的祖先。它返回一个包含匹配元素的新选择对象。

func (*Selection) ParentsFilteredUntil 
func (s *Selection) ParentsFilteredUntil(filterSelector, untilSelector string) *Selection
// ParentsFilteredUntil类似于ParentsUntil,它具有根据选择器字符串过滤结果的选项。它返回一个包含匹配元素的新选择对象。

func (*Selection) ParentsFilteredUntilMatcher 
func (s *Selection) ParentsFilteredUntilMatcher(filter, until Matcher) *Selection
// ParentsFilteredUntilMatcher与ParentsUntilMatcher类似,具有基于匹配器过滤结果的选项。它返回一个包含匹配元素的新选择对象。

func (*Selection) ParentsFilteredUntilNodes 
func (s *Selection) ParentsFilteredUntilNodes(filterSelector string, nodes ...*html.Node) *Selection
// ParentsFilteredUntilNodes类似于ParentsUntilNodes,具有基于选择器字符串过滤结果的选项。它返回一个包含匹配元素的新选择对象。

func (*Selection) ParentsFilteredUntilSelection 
func (s *Selection) ParentsFilteredUntilSelection(filterSelector string, sel *Selection) *Selection
// ParentsFilteredUntilSelection类似于ParentsUntilSelection,具有根据选择器字符串筛选结果的选项。它返回一个包含匹配元素的新选择对象。

func (*Selection) ParentsMatcher 
func (s *Selection) ParentsMatcher(m Matcher) *Selection
// ParentsMatcher获取当前选择中每个元素的祖先。它返回一个包含匹配元素的新选择对象。

func (*Selection) ParentsMatcherUntilNodes 
func (s *Selection) ParentsMatcherUntilNodes(filter Matcher, nodes ...*html.Node) *Selection
// ParentsMatcherUntilNodes与ParentsUntilNodes类似,具有基于匹配器过滤结果的选项。它返回一个包含匹配元素的新选择对象。

func (*Selection) ParentsMatcherUntilSelection 
func (s *Selection) ParentsMatcherUntilSelection(filter Matcher, sel *Selection) *Selection
// ParentsMatcherUntilSelection类似于ParentsUntilSelection,具有基于匹配器过滤结果的选项。它返回一个包含匹配元素的新选择对象。

func (*Selection) ParentsUntil 
func (s *Selection) ParentsUntil(selector string) *Selection
// ParentsUntil获取选择中每个元素的祖先,直到但不包括选择器匹配的元素。它返回一个包含匹配元素的新选择对象。

func (*Selection) ParentsUntilMatcher 
func (s *Selection) ParentsUntilMatcher(m Matcher) *Selection
// ParentsUntilMatcher获取选择中每个元素的祖先,直到但不包括匹配器匹配的元素。它返回一个包含匹配元素的新选择对象。

func (*Selection) ParentsUntilNodes 
func (s *Selection) ParentsUntilNodes(nodes ...*html.Node) *Selection
// ParentsUntilNodes获取所选内容中每个元素的祖先,最多包括但不包括指定的节点。它返回一个包含匹配元素的新选择对象。

func (*Selection) ParentsUntilSelection 
func (s *Selection) ParentsUntilSelection(sel *Selection) *Selection
// ParentsUntilSelection获取选择中每个元素的祖先,最多包括但不包括指定选择中的元素。它返回一个包含匹配元素的新选择对象。

func (*Selection) Prepend 
func (s *Selection) Prepend(selector string) *Selection
// Prepend将选择器指定的元素预先添加到匹配元素集中的每个元素,遵循与Append相同的规则。

func (*Selection) PrependHtml 
func (s *Selection) PrependHtml(htmlStr string) *Selection
// PrependHtml解析html并将其前置到匹配元素集。

func (*Selection) PrependMatcher 
func (s *Selection) PrependMatcher(m Matcher) *Selection
// PrependMatcher将匹配器指定的元素前置到匹配元素集中的每个元素。
// 这遵循与Selection.Append相同的规则。

func (*Selection) PrependNodes 
func (s *Selection) PrependNodes(ns ...*html.Node) *Selection
// PrependNodes将指定的节点前置到匹配元素集中的每个节点。
// 这遵循与Selection.Append相同的规则。

func (*Selection) PrependSelection 
func (s *Selection) PrependSelection(sel *Selection) *Selection
// PrependSelection将选择中的元素前置到匹配元素集中的每个元素。

// 这遵循与Selection.Append相同的规则。

func (*Selection) Prev 
func (s *Selection) Prev() *Selection
// Prev获取选择中每个元素的前一个同级。它返回一个包含匹配元素的新选择对象。

func (*Selection) PrevAll 
func (s *Selection) PrevAll() *Selection
// PrevAll获取选择中每个元素的所有前面的同级。它返回一个包含匹配元素的新选择对象。

func (*Selection) PrevAllFiltered 
func (s *Selection) PrevAllFiltered(selector string) *Selection
// PrevAllFiltered获取选择器筛选的选择中每个元素的所有前面的同级。它返回一个包含匹配元素的新选择对象。

func (*Selection) PrevAllMatcher 
func (s *Selection) PrevAllMatcher(m Matcher) *Selection
// PrevAllMatcher获取由匹配器过滤的选择中每个元素的所有前面的同级。它返回一个包含匹配元素的新选择对象。

func (*Selection) PrevFiltered 
func (s *Selection) PrevFiltered(selector string) *Selection
// PrevFiltered获取选择器筛选的选择中每个元素的前一个同级。它返回一个包含匹配元素的新选择对象。

func (*Selection) PrevFilteredUntil 
func (s *Selection) PrevFilteredUntil(filterSelector, untilSelector string) *Selection
// PrevFilteredUntil与PrevUntil类似,具有基于选择器字符串过滤结果的选项。它返回一个包含匹配元素的新选择对象。

func (*Selection) PrevFilteredUntilMatcher 
func (s *Selection) PrevFilteredUntilMatcher(filter, until Matcher) *Selection
// PrevFilteredUntilMatcher类似于PrevUntilMatcher,具有基于匹配器过滤结果的选项。它返回一个包含匹配元素的新选择对象。

func (*Selection) PrevFilteredUntilNodes 
func (s *Selection) PrevFilteredUntilNodes(filterSelector string, nodes ...*html.Node) *Selection
// PrevFilteredUntilNodes类似于PrevUntilNodes,具有基于选择器字符串过滤结果的选项。它返回一个包含匹配元素的新选择对象。

func (*Selection) PrevFilteredUntilSelection 
func (s *Selection) PrevFilteredUntilSelection(filterSelector string, sel *Selection) *Selection
// PrevFilteredUntilSelection与PrevUntilSelection类似,它具有根据选择器字符串过滤结果的选项。它返回一个包含匹配元素的新选择对象。

func (*Selection) PrevMatcher 
func (s *Selection) PrevMatcher(m Matcher) *Selection
// PrevMatcher获取由匹配器过滤的选择中每个元素的前一个同级。它返回一个包含匹配元素的新选择对象。

func (*Selection) PrevMatcherUntilNodes 
func (s *Selection) PrevMatcherUntilNodes(filter Matcher, nodes ...*html.Node) *Selection
// PrevMatcherUntilNodes与PrevUntilNodes类似,具有基于匹配器过滤结果的选项。它返回一个包含匹配元素的新选择对象。

func (*Selection) PrevMatcherUntilSelection 
func (s *Selection) PrevMatcherUntilSelection(filter Matcher, sel *Selection) *Selection
// PrevMatcherUntilSelection与PrevUntilSelection类似,具有基于匹配器过滤结果的选项。它返回一个包含匹配元素的新选择对象。

func (*Selection) PrevUntil 
func (s *Selection) PrevUntil(selector string) *Selection
// PrevTill获取每个元素的所有前面的同级,直到但不包括选择器匹配的元素。它返回一个包含匹配元素的新选择对象。

func (*Selection) PrevUntilMatcher 
func (s *Selection) PrevUntilMatcher(m Matcher) *Selection
// PrevUntilMatcher获取每个元素之前的所有同级,直到但不包括匹配器匹配的元素。它返回一个包含匹配元素的新选择对象。

func (*Selection) PrevUntilNodes 
func (s *Selection) PrevUntilNodes(nodes ...*html.Node) *Selection
// PrevUntilNodes获取每个元素之前的所有同级,直到但不包括节点匹配的元素。它返回一个包含匹配元素的新选择对象。

func (*Selection) PrevUntilSelection 
func (s *Selection) PrevUntilSelection(sel *Selection) *Selection
// PrevUntilSelection获取每个元素之前的所有同级,直到但不包括与所选内容匹配的元素。它返回一个包含匹配元素的新选择对象。

func (*Selection) Remove 
func (s *Selection) Remove() *Selection
// 移除从文档中移除匹配元素集。它返回相同的选择,现在由不在文档中的节点组成。

func (*Selection) RemoveAttr 
func (s *Selection) RemoveAttr(attrName string) *Selection
// RemoveAttr从匹配元素集中的每个元素中删除命名属性。

func (*Selection) RemoveClass 
func (s *Selection) RemoveClass(class ...string) *Selection
// RemoveClass从匹配元素集中的每个元素中移除给定的类。可以指定多个类名,用空格分隔或通过多个参数分隔。如果未提供类名,则删除所有类。

func (*Selection) RemoveFiltered 
func (s *Selection) RemoveFiltered(selector string) *Selection
// RemoveFiltered从当前匹配元素集中删除与选择器过滤器匹配的元素。它返回已删除节点的选择。
// 例如,如果选择s包含“<h1>”、“<h2>”和“<h3>”并且调用了s.RemoveFiltered(“h2”),则仅删除(并返回)“<h2>”节点,而“<h1>”和“<h3>”节点保留在文档中。

func (*Selection) RemoveMatcher 
func (s *Selection) RemoveMatcher(m Matcher) *Selection
// RemoveMatcher从当前匹配元素集中删除与Matcher筛选器匹配的元素。它返回已删除节点的选择。有关更多信息,请参见RemoveFiltered。

func (*Selection) ReplaceWith 
func (s *Selection) ReplaceWith(selector string) *Selection
// ReplaceWith使用给定选择器匹配的节点替换匹配元素集中的每个元素。它返回删除的元素。
// 这遵循与Selection.Append相同的规则。

func (*Selection) ReplaceWithHtml 
func (s *Selection) ReplaceWithHtml(htmlStr string) *Selection
// ReplaceWithHtml使用解析的HTML替换匹配元素集中的每个元素。它返回删除的元素。
// 这遵循与Selection.Append相同的规则。

func (*Selection) ReplaceWithMatcher 
func (s *Selection) ReplaceWithMatcher(m Matcher) *Selection
// ReplaceWithMatcher使用给定匹配器匹配的节点替换匹配元素集中的每个元素。它返回删除的元素。
// 这遵循与Selection.Append相同的规则。

func (*Selection) ReplaceWithNodes 
func (s *Selection) ReplaceWithNodes(ns ...*html.Node) *Selection
// ReplaceWithNodes使用给定节点替换匹配元素集中的每个元素。它返回删除的元素。
// 这遵循与Selection.Append相同的规则。

func (*Selection) ReplaceWithSelection 
func (s *Selection) ReplaceWithSelection(sel *Selection) *Selection
// ReplaceWithSelection使用给定选择中的节点替换匹配元素集中的每个元素。它返回删除的元素。
// 这遵循与Selection.Append相同的规则。

func (*Selection) SetAttr 
func (s *Selection) SetAttr(attrName, val string) *Selection
// SetAttr在匹配元素集中的每个元素上设置给定属性。

func (*Selection) SetHtml 
func (s *Selection) SetHtml(htmlStr string) *Selection
// SetHtml将选择中每个元素的html内容设置为指定的html字符串。

func (*Selection) SetText 
func (s *Selection) SetText(text string) *Selection
// SetText将选择中每个元素的内容设置为指定内容。将转义提供的文本字符串。

func (*Selection) Siblings 
func (s *Selection) Siblings() *Selection
// “同级”获取选择中每个元素的同级。它返回一个包含匹配元素的新选择对象。

func (*Selection) SiblingsFiltered 
func (s *Selection) SiblingsFiltered(selector string) *Selection
// SiblingsFiltered获取选择器筛选的选择中每个元素的同级。它返回一个包含匹配元素的新选择对象。

func (*Selection) SiblingsMatcher 
func (s *Selection) SiblingsMatcher(m Matcher) *Selection
// SiblingsMatcher获取由匹配器过滤的选择中每个元素的同级。它返回一个包含匹配元素的新选择对象。

func (*Selection) Size 
func (s *Selection) Size() int
// 大小是长度的别名。

func (*Selection) Slice 
func (s *Selection) Slice(start, end int) *Selection
// 切片将匹配元素集减少到由一系列索引指定的子集。起始索引是基于0的,指示要选择的第一个元素的索引。结束索引是基于0的,表示停止选择元素的索引(未选择结束索引)。
// 索引可能为负数,在这种情况下,它们表示从选择结束的偏移量。
// 特殊值ToEnd可以指定为结束索引,在这种情况下,直到结束的所有元素都被选中。这适用于正和负起始索引。

func (*Selection) Text 
func (s *Selection) Text() string
// Text获取匹配元素集中每个元素的组合文本内容,包括其子元素。

func (*Selection) ToggleClass 
func (s *Selection) ToggleClass(class ...string) *Selection
// ToggleClass为匹配元素集中的每个元素添加或删除给定类。可以指定多个类名,用空格分隔或通过多个参数分隔。

func (*Selection) Union 
func (s *Selection) Union(sel *Selection) *Selection
// Union是AddSelection的别名。

func (*Selection) Unwrap 
func (s *Selection) Unwrap() *Selection
// “展开”将删除匹配元素集的父元素,将匹配元素(及其同级元素,如果有)保留在原来的位置。它返回原始选择。

func (*Selection) Wrap 
func (s *Selection) Wrap(selector string) *Selection
// Wrap将匹配元素集中的每个元素包装在给定选择器匹配的第一个元素内。匹配的子项在插入文档之前被克隆。
// 它返回原始元素集。

func (*Selection) WrapAll 
func (s *Selection) WrapAll(selector string) *Selection
// WrapAll围绕匹配元素集中的所有元素包装一个由给定选择器匹配的HTML结构。匹配的子项在插入文档之前被克隆。
// 它返回原始元素集。

func (*Selection) WrapAllHtml 
func (s *Selection) WrapAllHtml(htmlStr string) *Selection
// WrapAllHtml围绕匹配元素集中的所有元素包装给定的HTML结构。匹配的子项在插入文档之前被克隆。
// 它返回原始元素集。

func (*Selection) WrapAllMatcher 
func (s *Selection) WrapAllMatcher(m Matcher) *Selection
// WrapAllMatcher围绕匹配元素集中的所有元素包装一个由给定匹配器匹配的HTML结构。匹配的子项在插入文档之前被克隆。
// 它返回原始元素集。

func (*Selection) WrapAllNode 
func (s *Selection) WrapAllNode(n *html.Node) *Selection
// WrapAllNode将给定节点环绕在选择中的第一个元素周围,使给定节点的选择子节点中的所有其他节点都处于活动状态。节点在插入到文档中之前被克隆。
// 它返回原始元素集。

func (*Selection) WrapAllSelection 
func (s *Selection) WrapAllSelection(sel *Selection) *Selection
// WrapAllSelection将单个HTML结构(给定选择的第一个节点)包装在匹配元素集中的所有元素周围。匹配的子项在插入文档之前被克隆。
// 它返回原始元素集。

func (*Selection) WrapHtml 
func (s *Selection) WrapHtml(htmlStr string) *Selection
// WrapHtml将匹配元素集中的每个元素包装在给定HTML的最内层子元素中。
// 它返回原始元素集。

func (*Selection) WrapInner 
func (s *Selection) WrapInner(selector string) *Selection
// WrapInner围绕匹配元素集中元素的内容包装一个由给定选择器匹配的HTML结构。匹配的子项在插入文档之前被克隆。
// 它返回原始元素集。

func (*Selection) WrapInnerHtml 
func (s *Selection) WrapInnerHtml(htmlStr string) *Selection
// wrapinnertml围绕匹配元素集中元素的内容包装一个由给定选择器匹配的HTML结构。匹配的子项在插入文档之前被克隆。
// 它返回原始元素集。

func (*Selection) WrapInnerMatcher 
func (s *Selection) WrapInnerMatcher(m Matcher) *Selection
// WrapInnerMatcher围绕匹配元素集中元素的内容包装一个由给定选择器匹配的HTML结构。匹配的子项在插入文档之前被克隆。
// 它返回原始元素集。

func (*Selection) WrapInnerNode 
func (s *Selection) WrapInnerNode(n *html.Node) *Selection
// WrapInnerNode围绕匹配元素集中元素的内容包装一个由给定选择器匹配的HTML结构。匹配的子项在插入文档之前被克隆。
// 它返回原始元素集。

func (*Selection) WrapInnerSelection 
func (s *Selection) WrapInnerSelection(sel *Selection) *Selection
// WrapInnerSelection围绕匹配元素集中元素的内容包装一个由给定选择器匹配的HTML结构。匹配的子项在插入文档之前被克隆。
// 它返回原始元素集。

func (*Selection) WrapMatcher 
func (s *Selection) WrapMatcher(m Matcher) *Selection
// WrapMatcher将匹配元素集中的每个元素包装在给定匹配器匹配的第一个元素内。匹配的子项在插入文档之前被克隆。
// 它返回原始元素集。

func (*Selection) WrapNode 
func (s *Selection) WrapNode(n *html.Node) *Selection
// WrapNode将匹配元素集中的每个元素包装在给定节点的最内层子节点中。在将给定节点插入文档之前,将复制该节点。
// 它返回原始元素集。

func (*Selection) WrapSelection 
func (s *Selection) WrapSelection(sel *Selection) *Selection
// WrapSelection将匹配元素集中的每个元素包装在给定选择中的第一个元素内。元素在插入到文档中之前被克隆。
// 它返回原始元素集。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值