Web crawler (4)--Regular expression

Source: Internet
Author: User
Tags net domain

Regular expressions are used extensively in text-matching. The web crawler often involves extracting some information from the page, and regular expressions can greatly simplify the process of filtering information.

Learn about regular expressions you can refer to http://www.runoob.com/python/python-reg-expressions.html we use the regular expression of a mailbox as an example to introduce the application of regular expressions. An email address can be broken down into the following rules:
  • the first part of the email address includes at least one content: uppercase letters, lowercase letters, numbers 0-9, Dot (.), plus (+), or underscore (_), and the corresponding regular expression is [a-za-z0-9\._+]+
  • after that, an @ symbol is included, and after @, the email address contains at least one uppercase or lowercase letter, corresponding to the regular type [a-za-z]+ , and then includes a dot number, ending with a com, org, edu, net domain name , (com|org|edu|net)
  • By summarizing these rules, you can get a regular expression that matches the mailbox:
[A-za-z0-9\._+][email protected][a-za-z]+\. ( com|org|edu|net) with this expression we can easily parse out the email address in the Web page without having to write a lot of character judgments . Regular expressions can be used not only independently, but also in BeautifulSoup, in fact, most functions that support string parameters can be implemented using regular expressions. as in BeautifulSoup's Find function, find ("img", {"src": re.compile ("xxx")} can be used to find an image that conforms to the rule.



From for notes (Wiz)



Web crawler (4)--Regular expression

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.