Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import httplib
- import re
- import string
- import sys
- import smtplib
- from email.mime.multipart import MIMEMultipart
- from email.mime.text import MIMEText
- from email.mime.application import MIMEApplication
- import base64
- import urllib2
- import requests
- #import argparse
- from urlparse import urlsplit
- from collections import deque
- from bs4 import BeautifulSoup
- #parser = argparse.ArgumentParser(description='Lead Gen Script - V1.0')
- #parser.add_argument('-l','--link', help='Google URL', required=True)
- #parser.add_argument('-c','--climit', help='Contact limit', required=True)
- #args = vars(parser.parse_args())
- #google_url = str(args['link'])
- google_links = []
- links = []
- google_url = str(raw_input("Google Maps URL: "))
- hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
- 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
- 'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
- 'Accept-Encoding': 'none',
- 'Accept-Language': 'en-US,en;q=0.8',
- 'Connection': 'keep-alive'}
- def getGoogleLinks(xurl):
- req = urllib2.Request(xurl, headers=hdr)
- html_page = urllib2.urlopen(req)
- soup = BeautifulSoup(html_page, "html.parser")
- for link in soup.findAll('a', attrs={'href': re.compile("^https://www.google.com/search")}):
- google_links.append(link.get('href'))
- return google_links
- google_links = getGoogleLinks(google_url)
- print("Lead Gen Script - V1.0")
- print("----------------------\n")
- from_email = "racinecountyeyenews@gmail.com"
- contact_limit=20 #CHANGE THIS TO THE DESIRED CONTACT LIMIT
- #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"
- #google_url = str(raw_input("Google Maps URL: "))
- print("")
- print("----------------------")
- j=0
- for google_link in google_links:
- def getLinks(url):
- req = urllib2.Request(url, headers=hdr)
- html_page = urllib2.urlopen(req)
- soup = BeautifulSoup(html_page, "html.parser")
- for link in soup.findAll('a', attrs={'href': re.compile("^http://")}):
- links.append(link.get('href'))
- return links
- mail_list = []
- url_list = []
- temp = getLinks(google_link)
- for starting_url in temp:
- try:
- j=j+1
- unprocessed_urls = deque([starting_url])
- processed_urls = set()
- i=0
- while len(unprocessed_urls):
- i=i+1
- url = unprocessed_urls.popleft()
- processed_urls.add(url)
- parts = urlsplit(url)
- base_url = "{0.scheme}://{0.netloc}".format(parts)
- path = url[:url.rfind('/')+1] if '/' in parts.path else url
- if i>20:
- break
- if j>=contact_limit:
- print(str(j)+" URLs - limit reached. Exiting...")
- sys.exit(0)
- print("Crawling URL: %s" % url)
- try:
- response = requests.get(url)
- except (requests.exceptions.MissingSchema, requests.exceptions.ConnectionError):
- continue
- print(str(re.findall(r"[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+", response.text, re.I)))
- if len(re.findall(r"[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+", response.text, re.I)) !=0:
- print(8)
- #mail_list.append(str(re.findall(r"[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+", response.text, re.I)))
- #print(str(re.findall(r"[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+", response.text, re.I)))
- s=str(re.findall(r"[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+", response.text, re.I))
- result0 = re.search("'(.*)'", s)
- q=str(result0.group(1))
- q=str(q.split("'")[0])
- mail_list.append(q)
- url_list.append(url)
- #mail_list.append(new_email)
- break
- soup = BeautifulSoup(response.text, 'lxml')
- for anchor in soup.find_all("a"):
- link = anchor.attrs["href"] if "href" in anchor.attrs else ''
- if link.startswith('/'):
- link = base_url + link
- elif not link.startswith('http'):
- link = path + link
- if not link in unprocessed_urls and not link in processed_urls:
- unprocessed_urls.append(link)
- except:
- pass
- def SendMail(to_email):
- #Authenticate to Gmail's SMTP Protocol
- #server = smtplib.SMTP('smtp.gmail.com', 587)
- #server.starttls()
- #Encrypt (Encode) Password to avoid plain-text exposure
- #server.login(("racinecountyeyenews@gmail.com"), ("RacineCountyEye123!"))
- # Create a text/plain message
- msg = MIMEMultipart('alternative')
- msg['Subject'] = 'Alex from Racine County Eye News, just reaching out to say hello'
- msg['From'] = from_email
- msg['To'] = to_email
- # Attaching the html
- html = """\
- <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:"Times New Roman";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 & Marketing Representative</span><span style=3D"font-size:11pt;font-family:"Times New Roman";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:"Times New Roman";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:"Times New Roman";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:"Times New Roman";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:"Times New Roman";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:"Times New Roman";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:"Times New Roman";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:"Times New Roman";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:"Times New Roman";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:"Times New Roman";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:"Times New Roman";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:"Times New Roman";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:"Times New Roman";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:"TimesNew Roman";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:"Times New Roman";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:"Times New Roman";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:"Times New Roman";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>"""
- # The main body is just another attachment
- #body = email.mime.Text.MIMEText("""Test body...""")
- part = MIMEText(html, 'html')
- msg.attach(part)
- ###### [COMMENT THE FOLLOW TO NOT INCLUDE ATTACHMENT] ###
- filename='More_Information.pdf'
- fp=open(filename,'rb')
- att = MIMEApplication(fp.read(),_subtype="pdf")
- fp.close()
- att.add_header('Content-Disposition','attachment',filename=filename)
- msg.attach(att)
- ######
- #Login
- s = smtplib.SMTP('smtp.gmail.com')
- s.starttls()
- s.login(from_email,'RacineCountyEye123!')
- s.sendmail(from_email,[to_email], msg.as_string())
- s.quit()
- mail_list = [str(x) for x in mail_list]
- url_list = [str(y) for y in url_list]
- print(mail_list)
- print("\nEmail Addresses fetched:")
- for address in mail_list:
- print(address)
- print("")
- for address in mail_list:
- if str(address) not in open("already_sent.txt").read():
- print "Sending mail to "+str(address)+"...",
- SendMail(str(address))
- with open("already_sent.txt", "a") as myfile:
- myfile.write(address+":"+url_list[(mail_list.index(address))]+'\n')
- print "Sent!\n"
- print("----------------------")
- print("Script finished successfully.")
Add Comment
Please, Sign In to add comment