-
Notifications
You must be signed in to change notification settings - Fork 0
/
real_bank_main.py
62 lines (57 loc) · 1.85 KB
/
real_bank_main.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
import requests
from bs4 import BeautifulSoup
import re
from real_bank import Real_bank
class main():
def __init__(self):
self.l2 = []
self.l4 = []
def parse_rate(self):
l = []
req = requests.get('https://10bestpersonalloans.com/go/bank_competitors_rates-usa-eng-d-g.html')
soup = BeautifulSoup(req.text, "html.parser")
percentage = soup.find_all('span')
for i in percentage:
text = i.get_text()
if '%' in text:
apr = text.strip()
l.append(apr)
(list(set(l)))
l2 = []
for j in l:
a1 = j[j.find('APR: ') + len('APR: '): j.rfind('% -')]
a2 = j[j.find(' - ') + len(' - '): j.rfind('%')]
avg_val = f'{(float(a1) + float(a2)) / 2: .2f}'
l2.append(avg_val)
l2 = list(set(l2))
return(l2)
def parse_name(self):
req = requests.get('https://10bestpersonalloans.com/go/bank_competitors_rates-usa-eng-d-g.html')
soup = BeautifulSoup(req.text, "html.parser")
l3 = []
l4 = []
names = soup.find_all('span', {'class': 'Card1_simpleText__S5PZY'})
for n in names:
tag = re.findall(re.escape('>') + "(.*)" + re.escape('<'), str(n))[0]
l3.append(tag)
for m in l3:
if 'Visit' in m:
m = m[6:]
l4.append(m)
else:
m = 'A Company ' + m
l4.append(m)
del l4[len(self.l2)-1:]
return(l4)
def getBanks():
rates = main().parse_rate()
names = main().parse_name()
banks = []
for i in range(0, len(rates)):
banks.append(Real_bank(names[i],rates[i]))
return banks
if __name__ == '__main__':
banks = getBanks()
for bank in banks:
print(bank.getName())
print(bank.getRate())