-
Notifications
You must be signed in to change notification settings - Fork 4
/
main_withoutselenium.py
66 lines (54 loc) · 2.11 KB
/
main_withoutselenium.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
import requests
from bs4 import BeautifulSoup
import csv
for i in range(1,3909):
address = "https://www.venturein.or.kr/venturein/infor/C22100.do?pageIndex=" + str(i)
req = requests.get(address)
html = req.text
soup = BeautifulSoup(html, 'html.parser')
summary_info = soup.find('div', {"class":"board_table pb50"})
summary_info_list = summary_info.findAll('td')
for i in range(0,10):
data = str(summary_info_list[1 + i * 5]).split("venid=")[1]
data2 = data.split("menu=1\">")[1]
data2 = data2.split("</a")[0]
data = data.split("&")[0]
data = data.replace(' ','')
data = [data, data2]
page_id = "https://www.venturein.or.kr/venturein/infor/C21221.do?venid="+data[0]+"&menu=1"
print(page_id)
req = requests.get(page_id)
html = req.text
soup = BeautifulSoup(html, 'html.parser')
summary_info = soup.find_all('td', {"class": "t_center"})
summary=[]
count = 3
sum = 0
for i in range(1,4):
if summary_info[i].text=='':
summary.append(0.0)
else:
summary.append(float(summary_info[i].text))
if summary[i-1]==0.0:
count = count - 1
sum += summary[i-1]
if count == 0:
count = 1
sum = sum / count
print("3개년 증가율의 평균", sum)
income = soup.find_all('td', {"class": "t_right"})
try:
if len(income[7].text) > 3:
income = (income[7].text).replace(',', '')
income=int(income[7].text)
if income == 0:
future_income = 'x'
continue
future_income = (float(sum / 100) * income) + income
print("n년 후 예상 수익:", future_income)
except IndexError:
future_income='x'
full_data=[data,summary,future_income]
with open('output.csv', 'a', encoding="utf8") as file:
writer = csv.writer(file)
writer.writerow(full_data)