forked from attrib07/Acquisitions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathacquisitions.py
58 lines (51 loc) · 1.71 KB
/
acquisitions.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
import requests
from optparse import OptionParser
import re
def getUserInput():
parser = OptionParser()
parser.add_option('-c', dest = 'company', type = 'string', help = 'Enter `-c domain` to get its acquisitions')
(options, args) = parser.parse_args()
if not options.company:
raise SystemExit
else:
return options.company
def send_request(url):
headers = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:82.0) Gecko/20100101 Firefox/82.0"}
req = requests.get(url, headers=headers)
content = req.text
return content
# Get Company Name
def get_company_name(content):
content = content
# print(content)
names = []
companies = re.findall('(?:<strong class="c_identityChip-name">)(.*?)</strong>', content)
for line in companies:
line = line.lower()
if company not in line:
if line not in names:
names.append(line)
return(names)
# Get Company Date
def get_company_date(content):
content = content
dates = []
date = re.findall('(?:<span>20)(.*?)</span>', content)
for line in date:
dates.append(line)
return dates
if __name__ == "__main__":
company = getUserInput()
company = company.split('.')[0]
company_cap = company.capitalize()
acq_ulr = "https://index.co/company/" + company_cap +"/acquirees"
content = send_request(acq_ulr)
name = get_company_name(content)
date = get_company_date(content)
if name:
res = dict(zip(name, date))
print("Acquisitions for " + company + " are:\n")
for acq in res:
print("Company Name: " + acq + "\nAcquired on: 20" + res[acq] + "\n")
else:
print("No Acquisitions Found !\n")