Difference between Python Xpath and Regex, pythonxpathregex

Source: Internet
Author: User

Difference between Python Xpath and Regex, pythonxpathregex

When crawling webpage information, we often need to use Regex or Xpath.

Differences between the two:

RegexItself isText matching toolBecause it needs to be matched multiple times, it appliesShort and centralized information. It can be precisely matched and captured. HoweverLarge Capacity,Scattered contentHTML and other text, the efficiency will become very low.

XpathUnlike Regex, itXML processing toolBecause HTML is a real subset of XML, it also applies to HTML. From this we can see that the application scope of Xpath is much lower than that of Regex. However, when the application scope is small, it is often more targeted. Xpath traverses XML through the tree structure, and the crawling efficiency of webpage information will be much higher.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.