-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDartFinder.py
88 lines (67 loc) · 2.59 KB
/
DartFinder.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
import win32com.client
import requests
from bs4 import BeautifulSoup
from selenium import webdriver
import os
import time
import re
excel = win32com.client.Dispatch("Excel.Application")
excel.Visible = True
Datafile = os.getcwd() + "\기업리스트.xlsx"
wb = excel.Workbooks.Open(Datafile)
ws = wb.ActiveSheet
used = ws.UsedRange
nrows = used.Row + used.Rows.Count - 1
ncols = used.Column + used.Columns.Count - 1
inputfile = os.getcwd() + "\chromedriver"
driver = webdriver.Chrome(inputfile)
driver.implicitly_wait(3)
for i in range(1, nrows + 1):
if ws.Cells(i, 1).Value is None :
break
http = 'http://dart.fss.or.kr/html/search/SearchCompanyIR3_M.html?textCrpNM=' + ws.Cells(i, 1).Value
driver.get(http)
driver.execute_script("openSearchCorpWindow();")
time.sleep(5)
html = driver.page_source
soup = BeautifulSoup(html, 'html.parser')
prodList = soup.find_all("p", "page_info")
for s in prodList:
Test = re.findall("\d+", str(s))
if not Test:
ws.Cells(i, 2).Value = 0
break
ws.Cells(i, 2).Value = int(Test[2])
if int(Test[2]) > 0:
ws.Cells(i, 2).Interior.ColorIndex = 44
cropList = soup.select('#corpListContents > div > fieldset > div.table_scroll > table > tbody > tr')
cols = 3
colorCount = 35
for tr in cropList:
crpName = tr.find_all('input')
for Name in crpName:
ws.Cells(i, cols).Value = Name["value"]
ws.Cells(i, cols).Interior.ColorIndex = colorCount
cols = cols + 1
break
img = tr.find_all('img')
for g in img:
ws.Cells(i, cols).Value = g["alt"]
ws.Cells(i, cols).Interior.ColorIndex = colorCount
cols = cols + 1
tds = tr.find_all('td')
ws.Cells(i, cols).Value = tds[1].string
ws.Cells(i, cols).Interior.ColorIndex = colorCount
cols = cols + 1
ws.Cells(i, cols).Value = tds[2].string
ws.Cells(i, cols).Interior.ColorIndex = colorCount
cols = cols + 1
ws.Cells(i, cols).Value = tds[3].string
ws.Cells(i, cols).Interior.ColorIndex = colorCount
cols = cols + 1
colorCount = ((colorCount + 34) % 4) + 35
print("☆★☆★☆ 다트 검색 완료 ☆★☆★☆ ")
driver.close()
outputfile = os.getcwd() + "\다트검색_기업리스트.xlsx"
wb.SaveAs(outputfile)
excel.Quit()