colly框架依赖goquery库,goquery将jQuery的语法和特性引入到了go语言中。如果要灵活自如地采集数据,首先要了解jQuery选择器。以下内容是翻译jQuery官方网站

《Category: Selectors》章节内容:

Category: Selectors

 

Borrowing from CSS 1–3, and then adding its own, jQuery offers a powerful set of tools for matching a set of elements in a document.

To use any of the meta-characters ( such as  !"#$%&'()*+,./:;<=>?@[\]^`{|}~ ) as a literal part of a name, it must be escaped with with two backslashes: \\. For example, an element with >CSS character escape sequences for identifiers.

类别:选择器

CSS 1-3借用,然后添加它自己jQuery提供了一套强大的工具来匹配文档中的一组元素。要使用任何元字符(如 !"#$%&'()*+,./:;<=>?@[\]^`{|}~ )作为名称的文字部分,例如,一个id =foo.bar”的元素可以使用选择符$("#foo\\.bar")W3C CSS规范包含了关于有效的CSS选择器的完整规则。Mathias Bynens的关于标识符CSS字符转义序列的博文也是很有用的。

 

Also in: Selectors > Basic

All Selector (“*”)

Selects all elements.

Also in: Selectors > Basic Filter | Selectors > jQuery Extensions

选择所要元素

:animated Selector

Select all elements that are in the progress of an animation at the time the selector is run.

Also in: Selectors > Attribute

选择所有动画元素

Attribute Contains Prefix Selector [name|=”value”]

Selects elements that have the specified attribute with a value either equal to a given string or starting with that string followed by a hyphen (-).

Also in: Selectors > Attribute

属性包含前缀选择器 [name|=”value”]

选择具有指定属性的元素,其值等于给定的字符串,或者以该字符串开头,后跟连字符( - )。

Attribute Contains Selector [name*=”value”]

Selects elements that have the specified attribute with a value containing a given substring.

Also in: Selectors > Attribute

属性包含选择器 [name*=”value”]

选择具有指定属性的元素,其值包含给定子字符串。

Attribute Contains Word Selector [name~=”value”]

Selects elements that have the specified attribute with a value containing a given word, delimited by spaces.

Also in: Selectors > Attribute

属性包含字选择器[name~=”value”]

选择具有指定属性的元素,其值包含由空格分隔的给定单词。

 

Attribute Ends With Selector [name$=”value”]

Selects elements that have the specified attribute with a value ending exactly with a given string. The comparison is case sensitive.

Also in: Selectors > Attribute

 

属性结束选择器[name$=”value”]

选择具有指定属性的元素,其值以给定字符串结尾,精确匹配。比较区分大小写。

 

Attribute Equals Selector [name=”value”]

Selects elements that have the specified attribute with a value exactly equal to a certain value.

Also in: Selectors > Attribute | Selectors > jQuery Extensions

属性等于选择器[name=”value”]

选择具有指定属性的元素,其值恰好等于给定值。

 

Attribute Not Equal Selector [name!=”value”]

Select elements that either don’t have the specified attribute, or do have the specified attribute but not with a certain value.

Also in: Selectors > Attribute

属性不等于选择器[name!=”value”]

选择不具有指定属性的元素,或者具有指定属性但不具有特定值的元素。

 

Attribute Starts With Selector [name^=”value”]

Selects elements that have the specified attribute with a value beginning exactly with a given string.

Also in: Selectors > Form | Selectors > jQuery Extensions

 

属性以开始选择器[name^=”value”]

选择具有指定属性的元素,其值的开始部分与给定字符串完全一致。

 

:button Selector

Selects all button elements and elements of type button.

Also in: Selectors > Form | Selectors > jQuery Extensions

 

按钮选择器

选择所有按钮元素和类型按钮的元素。

:checkbox Selector

Selects all elements of type checkbox.

Also in: Selectors > Form

复选框选择器

选择所有复选框

:checked Selector

Matches all elements that are checked or selected.

Also in: Selectors > Hierarchy

匹配所有选中的元素。

 

Child Selector (“parent > child”)

Selects all direct child elements specified by “child” of elements specified by “parent”.

Also in: Selectors > Basic

选择由parent”指定元素的所有直接“child指定子元素。

Class Selector (“.class”)

Selects all elements with the given class.

Also in: Selectors > Content Filter

选择指定类的所有元素。

 

:contains() Selector

Select all elements that contain the specified text.

Also in: Selectors > Hierarchy

选择包含指定文本的所有元素

Descendant Selector (“ancestor descendant”)

Selects all elements that are descendants of a given ancestor.

Also in: Selectors > Form

后代选择器 (“ancestor descendant”)

选择指定祖先的所有后代元素

:disabled Selector

Selects all elements that are disabled.

Also in: Selectors > Basic

选择所有被禁用的元素。

Element Selector (“element”)

Selects all elements with the given tag name.

Also in: Selectors > Content Filter

元素选择器

选择指定标签名的所有元素

:empty Selector

Select all elements that have no children (including text nodes).

Also in: Selectors > Form

空选择器

选择所有没有子项的元素(包括文本节点)

:enabled Selector

Selects all elements that are enabled.

Also in: Selectors > Basic Filter | Selectors > jQuery Extensions

选择所有启用的元素

:eq() Selector

Select the element at index n within the matched set.

Also in: Selectors > Basic Filter | Selectors > jQuery Extensions

选择匹配集中index =n的元素(下标从0开始)。

:even Selector

Selects even elements, zero-indexed. See also odd.

Also in: Selectors > Form | Selectors > jQuery Extensions

选择偶数元素,下标从0开始。

:file Selector

Selects all elements of type file.

Also in: Selectors > Child Filter

选择所有文件类型的元素

:first-child Selector

Selects all elements that are the first child of their parent.

Also in: Selectors > Child Filter

选择所有父节点的第一个孩子元素。

:first-of-type Selector

Selects all elements that are the first among siblings of the same element name.

Also in: Selectors > Basic Filter | Selectors > jQuery Extensions

选择同一元素名称的所有兄弟节点中的第一个元素。

:first Selector

Selects the first matched DOM element.

Also in: Selectors > Basic Filter | Selectors > Form

选择第一个匹配的DOM元素。

:focus Selector

Selects element if it is currently focused.

Also in: Selectors > Basic Filter | Selectors > jQuery Extensions

选择指定元素,当前处于获取焦点状态

:gt() Selector

Select all elements at an index greater than index within the matched set.

Also in: Selectors > Attribute

选择匹配集中所有索引大于指定index值的元素。

Has Attribute Selector [name]

Selects elements that have the specified attribute, with any value.

Also in: Selectors > Content Filter | Selectors > jQuery Extensions

选择具有指定属性的所有元素,可以是任何值。

:has() Selector

Selects elements which contain at least one element that matches the specified selector.

Also in: Selectors > Basic Filter | Selectors > jQuery Extensions

选择指定元素,其包含至少一个元素匹配给定选择器。

:header Selector

Selects all elements that are headers, like h1, h2, h3 and so on.

Also in: Selectors > jQuery Extensions | Selectors > Visibility Filter

选择所有标题元素,例如h1,h2,h3

:hidden Selector

Selects all elements that are hidden.

Also in: Selectors > Basic

选择所有隐藏的元素

ID Selector (“#id”)

Selects a single element with the given id attribute.

Also in: Selectors > Form | Selectors > jQuery Extensions

选择具有给定id属性的单个元素。

:image Selector

Selects all elements of type image.

Also in: Selectors > Form | Selectors > jQuery Extensions

选择所有image类型的元素

:input Selector

Selects all input, textarea, select and button elements.

Also in: Selectors > Basic Filter

选择所有input, textarea, select 和button元素。

:lang() Selector

Selects all elements of the specified language.

Also in: Selectors > Child Filter

选择所有指定语言的元素。

:last-child Selector

Selects all elements that are the last child of their parent.

Also in: Selectors > Child Filter

选择所有父元素的最后一个孩子节点元素。

:last-of-type Selector

Selects all elements that are the last among siblings of the same element name.

Also in: Selectors > Basic Filter | Selectors > jQuery Extensions

选择同一元素名称的所有兄弟节点中的最后一个元素。

:last Selector

Selects the last matched element.

Also in: Selectors > Basic Filter | Selectors > jQuery Extensions

选择最后一个匹配的元素。

:lt() Selector

Select all elements at an index less than index within the matched set.

Also in: Selectors > Attribute

在匹配集中选择所有索引小于给定值的元素。

Multiple Attribute Selector [name=”value”][name2=”value2″]

Matches elements that match all of the specified attribute filters.

Also in: Selectors > Basic

多属性选择器

符合所有指定属性过滤器的匹配元素集。

Multiple Selector (“selector1, selector2, selectorN”)

Selects the combined results of all the specified selectors.

Also in: Selectors > Hierarchy

多重选择器

选择所有指定选择器的组合结果。

Next Adjacent Selector (“prev + next”)

Selects all next elements matching “next” that are immediately preceded by a sibling “prev”.

Also in: Selectors > Hierarchy

选择所有下一个匹配next”的元素,紧接在兄弟“prev之后。

Next Siblings Selector (“prev ~ siblings”)

Selects all sibling elements that follow after the “prev” element, have the same parent, and match the filtering “siblings” selector.

Also in: Selectors > Basic Filter

选择prev”元素之后的所有同级元素,具有相同的父级,并匹配筛选“siblings”选择器。

 

:not() Selector

Selects all elements that do not match the given selector.

Also in: Selectors > Child Filter

选择不匹配给定选择器的所有元素。

:nth-child() Selector

Selects all elements that are the nth-child of their parent.

Also in: Selectors > Child Filter

选择所有父元素的第n个子元素。

:nth-last-child() Selector

Selects all elements that are the nth-child of their parent, counting from the last element to the first.

Also in: Selectors > Child Filter

选择所有父元素的第n个子元素,从后向前计数。

:nth-last-of-type() Selector

Selects all the elements that are the nth-child of their parent in relation to siblings with the same element name, counting from the last element to the first.

Also in: Selectors > Child Filter

选择父元素的具有相同指定元素名称的子元素中第n个元素,按照从后向前的顺序计数。

:nth-of-type() Selector

Selects all elements that are the nth child of their parent in relation to siblings with the same element name.

Also in: Selectors > Basic Filter | Selectors > jQuery Extensions

选择父元素的具有相同指定元素名称的子元素中第n个元素

:odd Selector

Selects odd elements, zero-indexed. See also even.

Also in: Selectors > Child Filter

选择所有奇数元素,下标从0开始。

:only-child Selector

Selects all elements that are the only child of their parent.

Also in: Selectors > Child Filter

选择所有父元素的唯一孩子元素。

:only-of-type Selector

Selects all elements that have no siblings with the same element name.

Also in: Selectors > Content Filter | Selectors > jQuery Extensions

选择没有相同元素名称的兄弟节点的所有元素。

:parent Selector

Select all elements that have at least one child node (either an element or text).

Also in: Selectors > Form | Selectors > jQuery Extensions

选择至少有一个孩子节点(元素或文本)的所有元素

:password Selector

Selects all elements of type password.

Also in: Selectors > Form | Selectors > jQuery Extensions

选择所有password类型的元素。

:radio Selector

Selects all elements of type radio.

Also in: Selectors > Form | Selectors > jQuery Extensions

选择所有radio类型的元素。

:reset Selector

Selects all elements of type reset.

Also in: Selectors > Basic Filter

选择所有reset类型的元素

:root Selector

Selects the element that is the root of the document.

Also in: Selectors > Form | Selectors > jQuery Extensions

选择文档的根节点元素。

:selected Selector

Selects all elements that are selected.

Also in: Selectors > Form | Selectors > jQuery Extensions

选择所有选中的元素。

:submit Selector

Selects all elements of type submit.

Also in: Selectors > Basic Filter

选择所有submit类型的元素。

:target Selector

Selects the target element indicated by the fragment identifier of the document’s URI.

Also in: Selectors > Form | Selectors > jQuery Extensions

选择由文档的URI的片段标识符指示的目标元素。

:text Selector

Selects all input elements of type text.

Also in: Selectors > jQuery Extensions | Selectors > Visibility Filter

选择所有text类型的input元素

:visible Selector

Selects all elements that are visible.

选择所有可见元素。

 

相关文章:

  • 2021-12-22
  • 2022-01-08
  • 2022-02-02
  • 2021-12-26
  • 2021-07-14
  • 2021-11-15
  • 2022-02-06
  • 2022-12-23
猜你喜欢
  • 2022-01-09
  • 2022-01-30
  • 2022-12-23
  • 2022-12-23
  • 2021-06-26
  • 2022-02-10
  • 2021-11-15
相关资源
相似解决方案