"Python" xpath-1

Source: Internet
Author: User
Tags xpath

1, coverage package implementation code Coverage (1) pip install coverage (2) Coverage run xx.py (test script file) (3) Coverage report-m print out Coverage Information Report (4) coverage in the console HTML generates a Htmlcov file in the same directoryfolder, open index.html in folders to view code coverage in a graphical interface 2, Xpath Understanding(1) XPath is a language that looks for information in an XML document. XPath is used to navigate through elements and attributes in an XML document. 3, XPath basic Syntax http://www.w3school.com.cn/example/xmle/books.xml (1) slash/select from the root node, representing the absolute path (2) double slash//relative path, as long as the condition of the display exercise:

Select all the parent elements are the BBB element syntax for DDD://DDD/BBB

<AAA>  
<
BBB/>  
<
CCC/>  
<
BBB/>  
<
DDD>  
<
BBB/>  
</
DDD>  
<
CCC>  
<
DDD>  
<
BBB/>  
<
BBB/>  
</
DDD>  
</
CCC>  
</
AAA>

Selects all BBB element syntax for the AAA's CCC:/aaa/ccc//bbb

<AAA>  
<
BBB/>  
<
CCC/>  
<
BBB/>  
<
DDD>  
<
BBB/>  
</
DDD>  
<
CCC>  
<
DDD>  
<
BBB/>  
<
BBB/>  
</
DDD>  
</
CCC>  
</
AAA>

(3) point "." Select the current node

(2) point "..." Select the parent node of the current node

(4) [@] Property Select all Category property choose the book element with the Category property to select All Properties category= "Web" or "category=" by selecting the book element with the category= "cooking" property Paperback "element selects a book element with any attribute select an element relative to an attribute that does not have a property lookup (5) find the first element

Select the first BBB element syntax under AAA:/aaa/bbb[1]

< AAA >  
<
BBB/>
<
BBB/>
<
BBB/>
<
BBB/>
</
AAA>

(6) Select the last BBB element under AAA syntax:/aaa/bbb[last ()]

< AAA >  
<
BBB/>
<
BBB/>
<
BBB/>
<
BBB/>
</
AAA>

(7) Select the second-lowest BBB element under AAA syntax:/aaa/bbb[last ()-1]

< AAA >  
<
BBB/>
<
BBB/>
<
BBB/>
<
BBB/>
</
AAA>

(8) Select the first two BBB element syntax under AAA:/aaa/bbb[position () <3]

< AAA >  
<
BBB/>
<
BBB/>
<
BBB/>
<
BBB/>
</
AAA>

(9) Obtain the CCC element syntax under the BBB under the AAA with the S attribute:/aaa/bbb/ccc[@s]

<AAA> 
<
BBB> 
<
CCCs = "1"/> 
<
CCCs = "2"/> 
<
CCCs = "3"/> 
<
CCCs = "4"/> 
<
CCCs = "5"/> 
<
CCC r = "a"/> 
</
BBB> 
<
CCC> 
<
BBB r = "a"/> 
<
BBB r = "B"/> 
<
BBB r = "C"/> 
</
CCC> 
<
BBB/> 
<
BBB/> 
</
AAA>

"Python" xpath-1

Related Article

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.