The example in this article describes the way the Django framework in Python uses an email address on a regular search page. Share to everyone for your reference. The implementation method is as follows:
Import re from django.shortcuts import render from Pattern.web import URL, DOM, ABS, Find_urls def index (Request): "" Find emails addresses in requested URLs or contact page "" "" error = ' emails = set () url_string = Request. Get.get (' url ', ') Email_regex = Re.compile (R ' [a-z0-9._%+-]+@[a-z0-9.-]+\.[ a-z]{2,6} ', re. IGNORECASE) # Use absolute URL or domain name URL = URL (url_string) if Url_string.startswith (' http ') Else URL (domain=url _string,protocol= ' http ') if Url_string:try:dom = Dom (Url.download (cached=true)) except Exception, E:error = e E Lse:contact_urls = {url.string} # Search Links of contacts page for link in Dom (' a '): if Re.search (R ' Contact|abo Ut ', Link.source, re. IGNORECASE): Contact_urls.add (ABS (Link.attributes.get (' href ', '), Base=url.redirect or url.string)) for Contact_u RL in Contact_urls: # download contacts page dom = Dom (URL (contact_url). Download (cached=true)) # Search emails in the The body of the page is in the DOM (' body ') [0].Content.split (' \ n '): Found = Email_regex.search (line) if Found:emails.add (Found.group ()) data = {' URL ': url_s Tring, ' emails ': emails, ' ERROR ': Error,} return render (Request, ' index.html ', data)
PS: Here again for you to provide 2 very convenient regular expression tools for your reference to use:
JavaScript Regular expression online test tool:
Http://tools.jb51.net/regex/javascript
Regular expression online generation tool:
Http://tools.jb51.net/regex/create_reg
I hope this article will help you with your Python programming.