This example describes how 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 refrom django.shortcuts import renderfrom pattern.web import URL, DOM, ABS, FIND_URLSDEF Index (Request): "" "Find E mail addresses in requested URL or the 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_s Tring,protocol= ' http ') if Url_string:try:dom = Dom (Url.download (cached=true)) except Exception, E:error = e Else : Contact_urls = {url.string} # Search Links of contact page to link in Dom (' a '): if Re.search (R ' contact|about ', Link.source, re. IGNORECASE): Contact_urls.add (ABS (Link.attributes.get (' href ', '), Base=url.redirect or url.string)) for Contac T_url in contact_urls: # download Contact page dom = dom (URL (contact_url). Download (cached=true)) # Search Emails In 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_stri Ng, ' emails ': emails, ' ERROR ': Error,} return render (Request, ' index.html ', data)
Hopefully this article will help you with Python programming.