R Language Crawler: A comparison of CSS methods and XPath methods (table Introduction)

Source: Internet
Author: User
Tags xpath

    • CSS selector vs. XPath usage
Target Matching Nodes CSS 3 XPath
All nodes ~ * //*
Find a level, level two, level three header node ,, h1,h2,h3 //h1,//h2,//h3
All P-Nodes <p> p //p
All child nodes of the P node <p>All nodes under the label p > * //p/*
Find all Li tags that contain attr attributes <li attr="~"> li[attr] li[@attr]
Find all Li tags with attr values of value <li attr="value"> li[attr=value] //li[@attr=‘value‘]
Find all div nodes with an ID value of item <div id="item"> div#item //div[@id=‘item‘]
Find all tags that contain foo in the class value <* class="foo blahblah"> .foo //*[contains(@class,‘foo‘)]
First P-node <p>the first of many<p> p:first-child //p[1]
Nth node of P The nth of <p> the numerous<p> p:nth-child //p[n]
All p nodes that have child node A <p><a></p> CSS cannot be implemented //p[a]
Find text content is the p node of "Web scraping" <p>Web Scraping</p> CSS cannot be implemented //p[text()="Web Scraping"]

R Language Crawler: A comparison of CSS methods and XPath methods (table Introduction)

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.