Web crawler _xpath Learning (3)

Source: Internet
Author: User
Tags first string floor function

Here are 22 examples of using XPath syntax:

(1) The basic XPath syntax is similar to locating a file in a file system, if the path is preceded by a slash/start, then the path represents an absolute path to an element

(2) If the path begins with a double slash////, then all elements in the document that meet the double slash//after rule (regardless of hierarchy) are selected

(3) asterisk * indicates that all elements positioned by the path before the asterisk are selected

(4) The expression in the block number can further specify the element, where the number represents the position of the element in the selection set, and the last () function represents the final element in the selection set.

(5) The attribute is specified by the prefix @

(6) The value of the attribute can be used as the criteria for selection, the Normalize-space function removes the front and trailing spaces, and replaces the contiguous space string with a single space

(7) Count () function to count the number of selected elements

(8) the name () function returns the names of the elements, and the Start-with () function returns True if the first argument string of the function starts with the second parameter character, and returns True when its first string argument contains a second string argument.

(9) String-length function returns the number of characters in a string, you should use &lt; instead of <, &gt; instead of >

(10) Multiple paths can be delimited | Merge together

The child axis (axis) contains the sub-elements of the context node, which, as the default axis, can be ignored and not written.

The descendant (descendant) axis contains descendants of the context node, a descendant of a child node or child node, and so on, so the descendant axis does not contain attributes and namespace nodes.

The parent axis (axis) contains the parents of the context node, if there is a parent node

The 14ancestor axis (axis) contains the ancestor nodes of the upper and lower nodes, which consist of the parent node of its context node and the parent node of the parent node, and so on, so the ancestor axis always contains the root node, unless the context node is the root node itself.

15.preceding-sibling axis (axis) contains all sibling nodes before the context node

16.following-sibling axis (axis) contains all sibling nodes after the context node

The 17.following axis (axis) contains all nodes in the same document that precede the context node in document order, in addition to ancestor nodes, attribute nodes, and namespace nodes

The 18.following axis (axis) contains all nodes in the same document that precede the context node in document order, in addition to ancestor nodes, attribute nodes, and namespace nodes

The 19.descendant-or-self axis (axis) contains the context node itself and the node's descendant nodes

The ancestor-or-self axis (axis) contains the context node itself and the node's ancestor node

Ancestor, descendant, following, preceding, and the self axis (axis) split the XML document (ignoring attribute nodes and namespace nodes), cannot overlap, and use together to include all nodes

The DIV operator does the floating-point division operation, the MoD operator does the remainder operation, the floor function returns the largest integer not greater than the parameter (toward positive infinity), and ceiling returns the smallest integer not less than the parameter (toward negative infinity)

Web crawler _xpath Learning (3)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.