-
Notifications
You must be signed in to change notification settings - Fork 1
/
zoominfo.py
226 lines (205 loc) · 9.53 KB
/
zoominfo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
from splinter import Browser
from bs4 import BeautifulSoup
import time
import pandas as pd
import difflib
import fuzzywuzzy
from fuzzywuzzy import fuzz
from fuzzywuzzy import process
from crawl import CompanyInfoCrawl
from google import Google
import requests
import tldextract
import re
import li
class Zoominfo:
def _clean(self, name):
name = name.split('(')[0]
name = name.split(',')[0]
name = name.split('\u')[0]
name = re.split('[^a-zA-Z\d\s\-]', name)[0]
return name
def _browser(self):
url = "http://www.zoominfo.com/s/#!search/company"
#browser = Browser('chrome')
browser = Browser('phantomjs')
browser.visit(url)
return browser
def _fill_variables(self, ):
''' lol - lmao'''
def __search(industry=False,locale=False,name=False,employees=False,revenue=False):
''' Search '''
browser = self._browser()
self._fill_variables()
def _fill_variables(self, name, industry=False, locale=False):
browser = self._browser()
if name: browser.find_by_name('companyName').first.fill(name)
if industry: browser.find_by_name('industryKeywords').first.fill(industry)
if locale: browser.find_by_name('address').first.fill(locale)
while not browser.find_by_css('div.big').visible:
if browser.is_text_present("No Results Found."): return "nope"
time.sleep(0.2)
return browser.html
def _zoominfo_search_html_to_df(self, html):
''' Parse Zoominfo Search Results Into DF '''
the_info = pd.DataFrame()
results = BeautifulSoup(html).find('table',{'id':'resultGroup'})
results = results.findAll('tr')
for result in results:
co = result.find('td',{'class':'name'})
if co == None: continue
name = co.find('a')
website = co.findAll('a')[-1] if len(co.findAll('a')) != 1 else ""
domain = co.findAll('a')[-1]
location = co.find('span',{'class':'companyAddress'})
revenue = co.find('span',{'class':'revenueText'})
employee_count = co.find('span',{'class':'employeeCount'})
description = result.find('td',{'class':'description'})
phone = BeautifulSoup(html).find('span',{'class':'companyContactNo'})
# change variables to parse db names
columns = ['name','website','domain','city','locale','revenue',
'headcount','description', 'phone']
values = [name, website, domain, location, location, revenue,
employee_count, description, phone]
values = [val.text if val else "" for val in values]
info = dict(zip(columns, values))
info['domain'] = "{}.{}".format(tldextract.extract(info['website']).domain, tldextract.extract(info['website']).tld)
info['source'] = "zoominfo"
the_info = the_info.append(info, ignore_index=True)
# Add Check for websiteUrl must be a proper domain
return the_info
def _get_best_match(self, company_name, df):
similar = difflib.get_close_matches(company_name,
[name for name in df.company_name])
if len(similar) and process.extract(company_name, similar)[0][1] > 80:
zoominfo_profile_name = process.extract(company_name, similar)[0][0]
for i, zoominfo_profile in df.iterrows():
if zoominfo_profile['company_name'] == zoominfo_profile_name:
return zoominfo_profile.to_dict()
return "not found"
def _company_profile(self, company_name, api_key="", domain=""):
qry = 'site:zoominfo.com/c/ {0}'.format(company_name)
google_df = Google().search(qry)
data = {'company_name':company_name, "domain":domain}
if google_df.empty:
return CompanyInfoCrawl()._persist(data,"zoominfo",api_key)
url = google_df.ix[0].link
print "ZOOMINFO URL", url
html = Google().ec2_cache(url)
html = requests.get(url).text
html = self._remove_non_ascii(html)
zoominfo = self._cache_html_to_df(html)
zoominfo['company_name'] = company_name
zoominfo['domain'] = domain
zoominfo['handle'] = url
print zoominfo
CompanyInfoCrawl()._persist(zoominfo, "zoominfo", api_key)
def _domain_search(self, domain, api_key="", name=""):
qry = 'site:zoominfo.com/c/ {0}'.format(domain)
df = Google().search(qry)
if df.empty:
data = {'company_name': name, "domain":domain}
return CompanyInfoCrawl()._persist(data,"zoominfo",api_key)
df['_name'] = [i.split("Company Profile")[0].strip()
for i in df.link_text]
df["score"] = [fuzz.ratio(b, name) for b in df._name]
df = df[df.score > 70]
df = df.sort('score',ascending=False)
if df.empty:
data = {'company_name': name, "domain":domain}
return CompanyInfoCrawl()._persist(data,"zoominfo",api_key)
df = df.reset_index().drop('index',1)
url = df.ix[0].link
print "ZOOMINFO URL", url
html = Google().cache(url)
html = requests.get(url).text
html = self._remove_non_ascii(html)
zoominfo = self._cache_html_to_df(html)
zoominfo['company_name'] = name
zoominfo['handle'] = url
zoominfo["domain_search"] = True
zoominfo["domain"] = domain
print zoominfo
CompanyInfoCrawl()._persist(zoominfo, "zoominfo", api_key)
def _remove_non_ascii(self, text):
return ''.join(i for i in text if ord(i)<128)
def _cache_html_to_df(self, html):
company = BeautifulSoup(html)
title = company.find('div',{'class':'companyTitle'})
description = company.find('div',{'class':'companyDescription'})
revenue = company.find('div',{'class':'companyRevenue'})
address = company.find('div',{'class':'companyAddress'})
employee_count = company.find('p',{'class':'companyEmployeeCountText'})
website = company.find('div',{'class':'website'})
phone = company.find('span',{'class':'hq'})
industries = company.find('p', {'class':'industry'})
industries = industries.find_all('span') if industries else []
industries = [industry.text for industry in industries]
data = [title, description, revenue, address, employee_count,
website, phone]
columns = ["name", "description", "revenue", "address",
"headcount","website","phone"]
# add industries
data = [val.text.strip() if val else "" for val in data]
data = dict(zip(columns, data))
data["industry"] = industries
print data
data["domain"] = "{}.{}".format(tldextract.extract(data["website"]).domain,
tldextract.extract(data["website"]).tld)
try:
data['logo'] = company.find('img',{'class':'companyLogo'})['src']
except:
data['logo'] = ""
data["source"] = "zoominfo"
data['headcount'] = data['headcount'].split('Employees')[0]
data['description'] = data['description'].split('Company Description')[-1]
data['revenue'] = data['revenue'].split('in Revenue')[0]
# add fullcontact address support
print data
return data
def _profile_to_df(self, html):
''' lol '''
title = company.find('h1',{'class':'companyName'})
description = company.find('span',{'class':'companyDesc'})
revenue = company.find('span',{'class':'revenueText'})
address = company.find('span',{'class':'companyAddress'})
employee_count = company.find('span',{'class':'employeeCount'})
website = company.find('div',{'class':'website'})
phone = company.find('span',{'class':'companyContactNo'})
data = [title, description, revenue, address, employee_count,
website, phone, url, logo]
columns = ["name", "description", "revenue", "address",
"address","employee_count","website","phone", "url", "logo"]
data = [val.text if val else "" for val in data]
data = dict(zip(columns, data))
data["domain"] = "{}.{}".format(tldextract.extract(data["website"]).domain,
tldextract.extract(data["website"]).tld)
data["source"] = "zoominfo"
try:
data['logo'] = company.find('img',{'class':'companyImgLogo'})['src']
except:
data['logo'] = ""
print data
return data
def _search(self, company_name):
name = self._clean(company_name)
zoominfo_html = self._fill_variables(company_name)
# click first
# companyResultsName
# scrape
def search(self, company_name):
'''
Input: Name and Possibly Location, Parse Object ObjectId
Output: Update Parse Object
'''
name = self._clean(company_name)
zoominfo_html = self._fill_variables(company_name)
#zoominfo_html = get_html_results_from_zoominfo(name)
if zoominfo_html == "nope": return "not found"
zoominfo_df = self._zoominfo_search_html_to_df(zoominfo_html)
best_match = self._get_best_match(name, zoominfo_df)
return best_match
# Get Email
# Update Parse With New Website and Phone Number
# r = requests.put('https://api.parse.com/1/classes/Prospects/'+objectId,
# headers=headers, params=json.dumps(zoominfo_profile))