SHARE
TWEET

Untitled

a guest Jan 25th, 2019 110 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import httplib
  2. import re
  3. import string
  4. import sys
  5. import smtplib
  6. from email.mime.multipart import MIMEMultipart
  7. from email.mime.text import MIMEText
  8. from email.mime.application import MIMEApplication
  9. import base64
  10. import urllib2
  11. import requests
  12. #import argparse
  13. from urlparse import urlsplit
  14. from collections import deque
  15. from bs4 import BeautifulSoup
  16.  
  17. #parser = argparse.ArgumentParser(description='Lead Gen Script - V1.0')
  18. #parser.add_argument('-l','--link', help='Google URL', required=True)
  19. #parser.add_argument('-c','--climit', help='Contact limit', required=True)
  20. #args = vars(parser.parse_args())
  21.  
  22. #google_url = str(args['link'])
  23.  
  24. google_links = []
  25. links = []
  26.  
  27. google_url = str(raw_input("Google Maps URL: "))
  28.  
  29. hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
  30.        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  31.        'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
  32.        'Accept-Encoding': 'none',
  33.        'Accept-Language': 'en-US,en;q=0.8',
  34.        'Connection': 'keep-alive'}
  35.  
  36. def getGoogleLinks(xurl):
  37.     req = urllib2.Request(xurl, headers=hdr)
  38.     html_page = urllib2.urlopen(req)
  39.     soup = BeautifulSoup(html_page, "html.parser")
  40.  
  41.     for link in soup.findAll('a', attrs={'href': re.compile("^https://www.google.com/search")}):
  42.         google_links.append(link.get('href'))
  43.  
  44.     return google_links
  45.  
  46. google_links = getGoogleLinks(google_url)
  47.  
  48. print("Lead Gen Script - V1.0")
  49. print("----------------------\n")
  50.  
  51. from_email = "racinecountyeyenews@gmail.com"
  52. contact_limit=20 #CHANGE THIS TO THE DESIRED CONTACT LIMIT
  53. #google_url = "https://www.google.com/search?rlz=1C1CHWL_en&q=construction%20companies%20in%20elkhorn%20wisconsin&npsic=0&rflfq=1&rlha=0&rllag=42679380,-88548678,3032&tbm=lcl&ved=2ahUKEwjTr6e99P_fAhVJmK0KHQF4DZQQjGp6BAgAEEg&tbs=lrf:!2m1!1e3!2m4!1e2!5m2!2m1!2e4!3sIAE,lf:1,lf_ui:2&rldoc=1&fll=0,0&fspn=0,NaN&fz=0&sll=0,0&sspn=0,NaN&sz=0&rlfi=hd:;si:&qop=0&rlvp=clear#qop=0&rlfi=hd:;si:&rlvp=clear"
  54. #google_url = str(raw_input("Google Maps URL: "))
  55. print("")
  56. print("----------------------")
  57. j=0
  58. for google_link in google_links:
  59.     def getLinks(url):
  60.         req = urllib2.Request(url, headers=hdr)
  61.         html_page = urllib2.urlopen(req)
  62.         soup = BeautifulSoup(html_page, "html.parser")
  63.  
  64.         for link in soup.findAll('a', attrs={'href': re.compile("^http://")}):
  65.             links.append(link.get('href'))
  66.  
  67.         return links
  68.  
  69.     mail_list = []
  70.     url_list = []
  71.     temp = getLinks(google_link)
  72.  
  73.     for starting_url in temp:
  74.         try:
  75.             j=j+1
  76.  
  77.             unprocessed_urls = deque([starting_url])
  78.             processed_urls = set()
  79.             i=0
  80.  
  81.             while len(unprocessed_urls):
  82.                 i=i+1
  83.  
  84.                 url = unprocessed_urls.popleft()
  85.                 processed_urls.add(url)
  86.  
  87.                 parts = urlsplit(url)
  88.                 base_url = "{0.scheme}://{0.netloc}".format(parts)
  89.                 path = url[:url.rfind('/')+1] if '/' in parts.path else url
  90.  
  91.                 if i>20:
  92.                     break
  93.                 if j>=contact_limit:
  94.                     print(str(j)+" URLs - limit reached. Exiting...")
  95.                     sys.exit(0)
  96.  
  97.                 print("Crawling URL: %s" % url)
  98.                 try:
  99.                     response = requests.get(url)
  100.                 except (requests.exceptions.MissingSchema, requests.exceptions.ConnectionError):
  101.                     continue
  102.                 print(str(re.findall(r"[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+", response.text, re.I)))
  103.                 if len(re.findall(r"[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+", response.text, re.I)) !=0:
  104.                     print(8)
  105.                     #mail_list.append(str(re.findall(r"[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+", response.text, re.I)))
  106.                     #print(str(re.findall(r"[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+", response.text, re.I)))
  107.                     s=str(re.findall(r"[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+", response.text, re.I))
  108.                     result0 = re.search("'(.*)'", s)
  109.                     q=str(result0.group(1))
  110.                     q=str(q.split("'")[0])
  111.                     mail_list.append(q)
  112.                     url_list.append(url)
  113.                     #mail_list.append(new_email)
  114.                     break
  115.                 soup = BeautifulSoup(response.text, 'lxml')
  116.  
  117.                 for anchor in soup.find_all("a"):
  118.                     link = anchor.attrs["href"] if "href" in anchor.attrs else ''
  119.                     if link.startswith('/'):
  120.                         link = base_url + link
  121.                     elif not link.startswith('http'):
  122.                         link = path + link
  123.                     if not link in unprocessed_urls and not link in processed_urls:
  124.                         unprocessed_urls.append(link)
  125.         except:
  126.             pass
  127.  
  128.  
  129.     def SendMail(to_email):
  130.         #Authenticate to Gmail's SMTP Protocol
  131.         #server = smtplib.SMTP('smtp.gmail.com', 587)
  132.         #server.starttls()
  133.  
  134.         #Encrypt (Encode) Password to avoid plain-text exposure
  135.         #server.login(("racinecountyeyenews@gmail.com"), ("RacineCountyEye123!"))
  136.  
  137.         # Create a text/plain message
  138.         msg = MIMEMultipart('alternative')
  139.         msg['Subject'] = 'Alex from Racine County Eye News, just reaching out to say hello'
  140.         msg['From'] = from_email
  141.         msg['To'] = to_email
  142.  
  143.         # Attaching the html
  144.         html = """\
  145. <html><head></head><body><div dir=3D"ltr"><span id=3D"gmail-docs-internal-guid-1bb3430c-7fff-13c1-95f1-f4eecfdbbf95"><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap">Hey there!</span><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap"><br></span><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap"><br></span><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap">Great website. I can tell you and your team haveput a lot of work to get to where you are today. I'll be as briefas possible because I don't want to waste your time.</span><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap"><br></span><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap"><br></span><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap"><br></span><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap">We're reaching out to local employers in the construction industry because we know many are suffering losses due to the trouble of finding and retaining skilled workers. It's not a mystery that high turnover canbe a huge cost to business, and we've been working hard on this new solution to fix that problem.</span><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap"><br></span><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;fontvariant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap"><br></span><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap"><br></span><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap">Starting on February 1st Racine County Eye News is sending out a newsletter directly to 50,000 job seekers in the Southeast Wisconsin Area. No other news organization is doing this and we have just obtained the right to do so.</span><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-weight:700;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap"> This tool can be customized to fitthe exact type of job seeker that you're looking to hire through location and income.</span><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap">This means we can even help you recruit in areas close to competitors. Because we're launching it in February, we're looking to advertise one or two local construction companies in these newsletters. </span><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);backgroundcolor:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap"><br></span><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap"><br></span><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap"><br></span><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap">To get straight to it, we are offering to place a 250 x 300 sized bannerpromoting your company in the newsletter sent to 50,000 job seekers for $250. Any number of months purchased in advance will be at the same price, even as that price increases in the future. Purchasing in advance will also ensure you retain your spot on the newsletter as space is so limited. </span><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap"><br></span><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap"><br></span><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap"><br></span><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap">Please feel free to ignore this message if it isn't of interest, and thank you for taking the time to read it. We just want to help thosewho are facing this problem to consider taking advantage of this easy solution. If this is of interest to you, feel free to send an email back or give me a call on my personal line. The sign up process is very easy and can be done either through the phone or directly on our website </span><a href="https://jobs.racinecountyeye.com/payments/new?p=3D78c8cfa5-bf72-4075-a62f-29fb0d55fa06" style=3D"text-decoration-line:none"><span style=3D"font-size:11pt;font-family:Arial;background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap">here</span></a><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap">.</span><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap"><br></span><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap"><br></span><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap"><br></span><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap"><br></span><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap">Thank you,</span><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap"><br></span><span style=3D"font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap"><br></span><span style=3D"font-size:11pt;font-family:&quot;Times New Roman&quot;;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap">Alex, Customer Relations &amp; Marketing Representative</span><span style=3D"font-size:11pt;font-family:&quot;Times New Roman&quot;;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;verticalalign:baseline;white-space:pre-wrap"><br></span><span style=3D"font-size:11pt;font-family:&quot;Times New Roman&quot;;color:rgb(0,0,0);background-color:transparent;font-weight:700;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap">Phone Number: </span><span style=3D"font-size:11pt;font-family:&quot;Times New Roman&quot;;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap">(262) 770-5175</span><span style=3D"font-size:11pt;font-family:&quot;Times New Roman&quot;;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap"><br></span><span style=3D"font-size:11pt;font-family:&quot;Times New Roman&quot;;color:rgb(0,0,0);background-color:transparent;font-weight:700;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap">CEO Denise Lockwood: </span><spanstyle=3D"font-size:11pt;font-family:&quot;Times New Roman&quot;;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap">(262) 504-9570</span><span style=3D"font-size:11pt;font-family:&quot;Times New Roman&quot;;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap"><br></span><span style=3D"font-size:11pt;font-family:&quot;Times New Roman&quot;;color:rgb(0,0,0);background-color:transparent;font-weight:700;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap">Email: </span><a href="mailto:Racinecountyeyenews@gmail.com" style=3D"text-decoration-line:none"><span style=3D"fontsize:11pt;font-family:&quot;Times New Roman&quot;;background-color:transparent;font-weight:700;font-variant-numeric:normal;font-variant-east-asian:normal;text-decoration-line:underline;vertical-align:baseline;white-space:prewrap">racinecountyeyenews@gmail.com</span></a></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style=3D"font-size:11pt;font-family:&quot;Times New Roman&quot;;color:rgb(0,0,0);background-color:transparent;font-weight:700;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap">Website: </span><a href="https://racinecountyeye.com" style=3D"text-decoration-line:none"><span style=3D"font-size:11pt;font-family:&quot;Times New Roman&quot;;background-color:transparent;font-weight:700;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap">https://racinecountyeye.com</span></a></p><p dir=3D"ltr" style=3D"line-height:1.38;margin-top:0pt;margin-bottom:0pt"><a href="https://jobs.racinecountyeye.com/" style=3D"text-decoration-line:none"><span style=3D"font-size:11pt;font-family:&quot;Times New Roman&quot;;background-color:transparent;font-weight:700;font-variant-numeric:normal;font-variant-east-asian:normal;text-decoration-line:underline;vertical-align:baseline;white-space:pre-wrap">Southeast Wisconsin Job Board</span></a><span style=3D"font-size:11pt;font-family:&quot;Times New Roman&quot;;font-weight:700;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap"> | </span><span style=3D"font-size:11pt;font-family:&quot;TimesNew Roman&quot;;color:rgb(0,0,0);background-color:transparent;font-weight:700;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap"> </span><a href="https://jobs.racinecountyeye.com/products" style=3D"text-decoration-line:none"><span style=3D"font-size:11pt;font-family:&quot;Times New Roman&quot;;background-color:transparent;font-weight:700;font-variant-numeric:normal;font-variant-east-asian:normal;text-decoration-line:underline;vertical-align:baseline;white-space:pre-wrap">Post a Job</span><span style=3D"font-size:11pt;font-family:&quot;Times New Roman&quot;;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap"><br></span><span style=3D"font-size:11pt;font-family:&quot;Times New Roman&quot;;color:rgb(0,0,0);background-color:transparent;font-variant-numeric:normal;font-variant-east-asian:normal;vertical-align:baseline;white-space:pre-wrap"><br><br></span></a><img src="https://lh4.googleusercontent.com/cMe1UvyguVslPKkrgYBraniFqOc-gKu5MHjZG_7VMMPJuVk82drGPjIWtnl2ruJDTwiA1zESoJZZFZu_MINoso7VRZLhMieVxwBbIyH_HOhC5h_nmGbsNcgTt1XwcKNAjhkNp0k" width="102" height="87" style="border: none; transform: rotate(0rad);"></p></span></div></body></html>"""
  146.  
  147.         # The main body is just another attachment
  148.         #body = email.mime.Text.MIMEText("""Test body...""")
  149.         part = MIMEText(html, 'html')
  150.         msg.attach(part)
  151.  
  152.         ###### [COMMENT THE FOLLOW TO NOT INCLUDE ATTACHMENT] ###
  153.         filename='More_Information.pdf'
  154.         fp=open(filename,'rb')
  155.         att = MIMEApplication(fp.read(),_subtype="pdf")
  156.         fp.close()
  157.         att.add_header('Content-Disposition','attachment',filename=filename)
  158.         msg.attach(att)
  159.         ######
  160.  
  161.         #Login
  162.         s = smtplib.SMTP('smtp.gmail.com')
  163.         s.starttls()
  164.         s.login(from_email,'RacineCountyEye123!')
  165.         s.sendmail(from_email,[to_email], msg.as_string())
  166.         s.quit()
  167.  
  168.     mail_list = [str(x) for x in mail_list]
  169.     url_list = [str(y) for y in url_list]
  170.     print(mail_list)
  171.     print("\nEmail Addresses fetched:")
  172.     for address in mail_list:
  173.         print(address)
  174.     print("")
  175.     for address in mail_list:
  176.         if str(address) not in open("already_sent.txt").read():
  177.             print "Sending mail to "+str(address)+"...",
  178.             SendMail(str(address))
  179.             with open("already_sent.txt", "a") as myfile:
  180.                 myfile.write(address+":"+url_list[(mail_list.index(address))]+'\n')
  181.             print "Sent!\n"
  182. print("----------------------")
  183. print("Script finished successfully.")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top