-
Notifications
You must be signed in to change notification settings - Fork 0
/
sites.py
1068 lines (892 loc) · 43.1 KB
/
sites.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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import re, time
from selenium.webdriver.common.keys import Keys
import requests
from bs4 import BeautifulSoup
from datetime import datetime
import mongo
import ssl
from urllib.request import urlopen
import message
from selenium import webdriver
# driver = webdriver.Chrome('C:/chromedriver')
today = datetime.now()
# ---------------------------- 동적인 웹 -----------------------
'''
msit,
kstartup
seoul
venture
ccei
'''
def msit_scan(driver):
name = '과학기술정보통신부'
try:
# 과학기술정보통신부 신청사업 url
url = 'https://msit.go.kr/web/msipContents/contents.do?mId=MTE5'
# 드라이버로 웹 열기
driver.get(url)
driver.implicitly_wait(3)
# 공지목록 가져오기
boards_list = driver.find_elements_by_xpath('//*[@id="result"]/div[2]/div/table/tbody/tr')
# 지난번 저장했던 포스트 가져오기
check_point = mongo.check_point_read(name)['title']
# 기준이될 point 저장
mongo.check_point_save(name, boards_list[0].find_element_by_class_name('title').text)
for x in boards_list:
title = x.find_element_by_class_name('title').text
if check_point != title:
date = '20' + x.find_element_by_xpath('./td[3]/span/span[3]').text + '.' + x.find_element_by_xpath(
'./td[3]/span/span[2]').text
link = x.find_element_by_tag_name('a').get_attribute('href')
mongo.post_save(name, title, link, date, '')
print('이름: ' + name + '\n제목:' + title + '\n링크: ' + link + '\n등록일: ' + date + '\n')
else:
break
except Exception:
message.site_error_push(name)
def kstartup_scan(driver):
name = 'kstartup'
# k- startup 신청게시판 url
url = 'http://www.k-startup.go.kr/common/announcement/announcementList.do?mid=30004&bid=701&searchAppAt=A'
board_url = 'http://www.k-startup.go.kr/common/announcement/announcementDetail.do?mid=30004&bid=701&searchPrefixCode=BOARD_701_001&searchPostSn='
# 드라이버로 웹 열기
driver.get(url)
driver.implicitly_wait(3)
driver.find_element_by_tag_name('body').send_keys(Keys.END)
# 지난번 저장했던 포스트 가져오기
check_point = mongo.check_point_read(name)['title']
point_flag = False
# 페이지 5회 이동
pagecount=0
while pagecount < 5:
driver.find_element_by_xpath('//*[@id="listPlusAdd"]/a').click()
driver.find_element_by_tag_name('body').send_keys(Keys.END)
time.sleep(1)
pagecount += 1
try:
# 중요 공지 가져오기
impo_board = driver.find_element_by_class_name('ann_list_impor')
boards_list = impo_board.find_elements_by_xpath('./li')
# 중요공지는 10개내외로 순차적이지않으므로, 제목을 비교하여 이전에것들을 제외시킨다.
for x in boards_list:
# 제목
title = x.find_element_by_tag_name('a').text.strip()
if mongo.is_saved(title) is None:
# 날짜 - 있는것과 없는것 구분처리
try:
due_date = re.findall("\d{4}-\d{2}-\d{2}", x.find_element_by_xpath('./ul/li[3]').text.strip())
date = due_date[0]
except Exception:
date = "상시모집"
# link - bi.net_url, kstartup_url 구분처리
params = re.findall("\d+", x.find_element_by_tag_name('a').get_attribute('href'))
if len(params) == 2: # bi-net 이동하는 함수일때, 파라미터가 2개임
link = "http://www.bi.go.kr/board/editView.do?boardVO.viewFlag=view&boardID=NOTICE&postSeq=" + \
params[0] + "®istDate=" + params[1]
elif len(params) > 2:
link = board_url + params[2]
else:
link = "링크오류"
mongo.post_save(name, title, link, '', date)
print('이름: ' + name + '\n제목:' + title + '\n링크: ' + link + '\n마감일: ' + date + '\n')
except Exception:
message.site_error_push(name + " < 중요공지부분 > ")
pass
try:
# 페이지별 공지 가져오기
ann_board = driver.find_element_by_class_name('ann_list')
boards_list2 = ann_board.find_elements_by_xpath('./li')
for x in boards_list2:
title = x.find_element_by_tag_name('a').text.strip()
if mongo.is_saved(title) is None and title != "":
# 날짜 있는것과 없는것 구분처리
try:
due_date = re.findall("\d{4}-\d{2}-\d{2}", x.find_element_by_xpath('./ul/li[3]').text.strip())
date = due_date[0]
except Exception:
date = "상시모집"
# bi.net_url, kstartup_url 구분처리
params = re.findall("\d+", x.find_element_by_tag_name('a').get_attribute('href'))
if len(params) == 2: # bi-net 이동하는 함수일때, 파라미터가 2개임
link = "http://www.bi.go.kr/board/editView.do?boardVO.viewFlag=view&boardID=NOTICE&postSeq=" + \
params[0] + "®istDate=" + params[1]
elif len(params) > 2:
link = board_url + params[2]
else:
link = "링크오류"
mongo.post_save(name, title, link, '', date)
print('이름: ' + name + '\n제목:' + title + '\n링크: ' + link + '\n마감일: ' + date + '\n')
else:
break
except Exception:
message.site_error_push(name + " < 일반 공지 부분 > ")
pass
def seoul_scan(driver):
names = ['서울특별시_고시공고']
try:
urls = ['http://www.seoul.go.kr/news/news_notice.do']
for i in range(1):
# 드라이버로 웹 열기
driver.get(urls[i])
driver.implicitly_wait(3)
# 공지목록 가져오기
boards_list = driver.find_elements_by_xpath('//*[@id="seoul-integrated-board"]/table/tbody/tr')
# 지난번 저장했던 포스트 가져오기
check_point = mongo.check_point_read(names[i])['title']
# 기준이될 point 저장
mongo.check_point_save(names[i], boards_list[0].find_element_by_tag_name('a').text.strip())
for x in boards_list:
title = x.find_element_by_tag_name('a').text.strip()
if check_point != title:
date = x.find_element_by_xpath('./td[4]').text
link = urls[i] + '#view/' + x.find_element_by_tag_name('a').get_attribute('data-nttgroup')
mongo.post_save(names[i], title, link, date, '')
print('이름: ' + names[i] + '\n제목:' + title + '\n링크: ' + link + '\n등록일: ' + date + '\n')
else:
break
except Exception:
message.site_error_push(names)
def venture_scan(driver):
# 벤처기업협회
names = ['벤처기업협회_사업공고']
try:
urls = ['https://www.venture.or.kr/#/home/bizNotice/h020101']
# 벤처기업협회_사업공고
driver.get(urls[0])
driver.implicitly_wait(3)
# 공지목록 가져오기
boards_list = driver.find_elements_by_xpath('//*[@id="contents"]/ui-view/div/div[2]/div[2]/div[1]/ul/li')
check_point = mongo.check_point_read(names[0])['title']
mongo.check_point_save(names[0], boards_list[0].find_element_by_tag_name('a').text)
for x in boards_list:
title = x.find_element_by_tag_name('a').text
if check_point != title:
link = x.find_element_by_tag_name('a').get_attribute('href')
date = x.find_element_by_css_selector('dd.info > span:nth-child(1)').text
try:
sdate = date.split(" ~ ").pop(0)
edate = date.split(" ~ ").pop(1)
except Exception: # 상시모집인 경우
sdate = date
edate = ''
mongo.post_save(names[0], title, link, sdate,edate)
print('이름: ' + names[0] + '\n제목:' + title + '\n링크: ' + link + '\n날짜: ' + date + '\n')
else:
break
except Exception:
message.site_error_push(names)
def ccei_scan(driver):
# 창조경제혁신센터
name = '창조경제혁신센터'
try:
url = 'https://ccei.creativekorea.or.kr/service/business_list.do'
urls = ['https://ccei.creativekorea.or.kr/service/business_view.do?seq=']
# pn=1&sPtime=now&pagePerContents=10&seq=3614&rownum=36
# 드라이버로 웹 열기
driver.get(url)
driver.implicitly_wait(3)
# 공지목록 가져오기
boards_list = driver.find_elements_by_xpath('//*[@id="list_body"]/tr')
# 지난번 저장했던 포스트 가져오기
check_point = mongo.check_point_read(name)['title']
# 기준이될 point 저장
mongo.check_point_save(name, boards_list[0].find_element_by_tag_name('a').text)
for x in boards_list:
title = x.find_element_by_tag_name('a').text
if check_point != title:
seq = re.findall('\d+', x.find_element_by_tag_name('a').get_attribute('onclick'))
link = urls[0] + seq[0]+"&rownum=" + seq[1]
date = x.find_element_by_xpath('./td[5]').text # 기간 (시작일 - 마감일)
try:
edate = date.split("~").pop(1)
sdate = date.split("~").pop(0)
# 형식이 다른경우
except Exception:
sdate = ''
edate = date
mongo.post_save(name, title, link, sdate, edate)
print('이름: ' + name + '\n제목:' + title + '\n링크: ' + link + '\n기간: ' + date + '\n')
else:
break
except Exception:
message.site_error_push(name)
# ----------------- 정적인 웹 크롤링 ---------------------------
'''
kotra, nipa, sba, kisa, nia, kdata, moel, bepa
'''
def kotra_scan():
# 코트라 사이트
name = 'Kotra'
try:
url = 'http://www.kotra.or.kr'
# 신청가능 사업 공지
req = requests.get(
'http://www.kotra.or.kr/kh/business/busiList.do?&MENU_CD=T0503&TOP_MENU_CD=T0500&LEFT_MENU_CD=T0503&PARENT_MENU_CD=&CO_TYPE=undefined&boardType=0')
html = req.text
soup = BeautifulSoup(html, 'html.parser')
# selector 로 데이터가저오기
titles = soup.select('td > a')
dates = soup.select('tr > td:nth-child(3)')
# 체크포인트 불러오기, 저장하기
mongo.check_point_save(name, titles[0].text.strip())
# 데이터 변수로 받아서 txt 저장
for i in range(len(titles)):
title = titles[i].text
link = url + titles[i].get('href').split('\'').pop(1)
date = dates[i].text
try:
sdate = date.split(" ~ ").pop(0)
edate = date.split(" ~ ").pop(1)
except Exception: # 상시모집인 경우
sdate = date
edate = ''
if mongo.is_saved(title) is None:
mongo.post_save(name, title, link, sdate, edate)
print('이름: ' + name + '\n제목: ' + title + '\n링크: ' + link + '\n신청기간: ' + date + '\n')
except Exception:
message.site_error_push(name)
def nipa_scan():
# 정보통신 산업진흥원 url
names = ['정보통신산업진흥원1', '정보통신산업진흥원2']
try:
url = 'http://www.nipa.kr'
uris = ['', '/biz/']
urls = ['http://www.nipa.kr/board/boardList.it?boardNo=103&menuNo=32&page=1',
'http://www.nipa.kr/biz/bizNotice.it?menuNo=18&page=1']
# 신청가능 사업 공지
for j in range(2):
req = requests.get(urls[j])
html = req.text
soup = BeautifulSoup(html, 'html.parser')
# selector 로 데이터가저오기
titles = soup.select('td > a')
dates = soup.select('tr > td.date')
# 체크포인트 불러오기, 저장하기
check_point = mongo.check_point_read(names[j])['title']
mongo.check_point_save(names[j], titles[0].text)
# 데이터 변수로 받아서 txt 저장
for i in range(len(titles)):
title = titles[i].text
link = url + uris[j] + titles[i].get('onclick').split('\'').pop(1)
date = dates[i].text
if mongo.is_saved(title) is None:
mongo.post_save(names[j], title, link, date, '')
print('이름: ' + names[j] + '\n제목: ' + title + '\n링크: ' + link + '\n등록일: ' + date + '\n')
except Exception:
message.site_error_push(names[0])
def sba_scan():
name = '서울산업진흥원'
try:
# 서울 산업 산업진흥원 url
url = 'http://www.sba.seoul.kr/kr/sbcu01l1'
# 신청가능 사업 공지
req = requests.get(url)
html = req.text
soup = BeautifulSoup(html, 'html.parser')
# selector 로 데이터가저오기
titles = soup.select('td > a')
dates = soup.select('tr > td:nth-child(3)')
# 체크포인트 불러오기, 저장하기
check_point = mongo.check_point_read(name)['title']
mongo.check_point_save(name, titles[0].text.strip())
# 데이터 변수로 받아서 txt 저장
for i in range(len(titles)):
title = titles[i].text.strip()
seq = re.findall("\d+", titles[i].get('onclick'))
link = "http://www.sba.seoul.kr/kr/sbcu01s1?bseq=" + seq[0]
date = dates[i].text
if check_point == title:
break
else:
mongo.post_save(name, title, link, date, '')
print('이름: ' + name + '\n제목: ' + title + '\n링크: ' + link + '\n등록일: ' + date + '\n')
except Exception:
message.site_error_push(name)
def kisa_scan():
# 한국인터넷진흥원 사이트
name = '한국인터넷진흥원'
try:
url = "https://www.kisa.or.kr"
# 신청가능 사업 공지
req = requests.get('https://www.kisa.or.kr/notice/notice_List.jsp')
html = req.text
soup = BeautifulSoup(html, 'html.parser')
# selector 로 데이터가저오기
titles = soup.select('td > a')
dates = soup.select('tr > td:nth-child(3)')
# 체크포인트 불러오기, 저장하기
check_point = mongo.check_point_read(name)['title']
mongo.check_point_save(name, titles[0].text.strip())
# 데이터 변수로 받아서 txt 저장
for i in range(len(titles)):
title = titles[i].text.strip()
link = url + titles[i].get('href')
date = dates[i].text.strip()
if check_point == title:
break
else:
mongo.post_save(name, title, link, date, '')
print('이름: ' + name + '\n제목: ' + title + '\n링크: ' + link + '\n등록일: ' + date + '\n')
except Exception:
message.site_error_push(name)
def nia_scan():
name = '한국정보화진흥원'
try:
# 한국 정보화 진흥원 url
url = 'https://www.nia.or.kr/site/nia_kor/ex/bbs/List.do?cbIdx=99835'
req = requests.get(url)
html = req.text
soup = BeautifulSoup(html, 'html.parser')
# selector 로 데이터가저오기
titles = soup.select('#sub_contentsArea > div.board_type01 > ul > li > a > span.subject')
params = soup.select('#sub_contentsArea > div.board_type01 > ul > li > a')
dates = soup.select('a > span.src > em:nth-child(1)')
# 체크포인트 불러오기, 저장하기
check_point = mongo.check_point_read(name)['title']
mongo.check_point_save(name, " ".join(titles[0].text.split())) # join과 split으로 중복 공백 제거
# 데이터 변수로 받아서 txt 저장
for i in range(len(titles)):
title = " ".join(titles[i].text.split()) # join과 split으로 중복 공백 제거
seq = re.findall('\d+', str(params[i].get('onclick')))
link = "https://www.nia.or.kr/site/nia_kor/ex/bbs/View.do?cbIdx=" + seq[0] + "&bcIdx=" + seq[
1] + "&parentSeq=" + seq[3]
date = dates[i].text
if check_point == title:
break
else:
mongo.post_save(name, title, link, date, '')
print('이름: ' + name + '\n제목: ' + title + '\n링크: ' + link + '\n등록일: ' + date + '\n')
except Exception:
message.site_error_push(name)
def kdata_scan():
name = '한국데이터산업진흥원'
try:
url = 'https://www.kdata.or.kr/board/notice_01.html'
context = ssl._create_unverified_context()
result = urlopen(url, context=context)
soup = BeautifulSoup(result.read(), "html.parser")
# selector 로 데이터가저오기
titles = soup.select('td > a')
dates = soup.select('tr > td.date')
# 체크포인트 불러오기, 저장하기
check_point = mongo.check_point_read(name)['title']
mongo.check_point_save(name, titles[0].text.strip())
# 데이터 변수로 받아서 txt 저장
for i in range(len(titles)):
title = titles[i].text.strip()
link = 'https://www.kdata.or.kr/board/' + titles[i].get('href')
date = dates[i].text
if check_point == title:
break
else:
mongo.post_save(name, title, link, date, '')
print('이름: ' + name + '\n제목: ' + title + '\n링크: ' + link + '\n등록일: ' + date + '\n')
except Exception:
message.site_error_push(name)
def moel_scan():
# 고용노동부 사이트
name = '고용노동부'
try:
url = 'http://www.moel.go.kr'
# 신청가능 사업 공지
req = requests.get('http://www.moel.go.kr/news/notice/noticeList.do')
html = req.text
soup = BeautifulSoup(html, 'html.parser')
# selector 로 데이터가저오기
titles = soup.select('td > a')
dates = soup.select('tr > td:nth-child(5)')
# 체크포인트 불러오기, 저장하기
check_point = mongo.check_point_read(name)['title']
mongo.check_point_save(name, titles[0].text.split("]").pop(1).strip())
# 데이터 변수로 받아서 txt 저장
for i in range(len(titles)):
title = titles[i].text.split("]").pop(1).strip()
link = url + titles[i].get('href')
date = dates[i].text
if check_point == title:
break
else:
mongo.post_save(name, title, link, date, '')
print('이름: ' + name + '\n제목: ' + title + '\n링크: ' + link + '\n등록일: ' + date + '\n')
except Exception:
message.site_error_push(name)
def bepa_scan():
name = '부산경제진흥원'
try:
url = 'https://www.bepa.kr/kor/view.do?no=209'
context = ssl._create_unverified_context()
result = urlopen(url, context=context)
soup = BeautifulSoup(result.read(), "html.parser")
# selector 로 데이터가저오기
titles = soup.select('td > a')
dates = soup.select('tr > td.date')
num = soup.select('td.num')
# 체크포인트 불러오기
check_point = mongo.check_point_read(name)['title']
# 데이터 변수로 받아서 txt 저장
for i in range(len(titles)):
if (num[i].text != "NOTICE"):
# 공지사항이 아닌 체크포인트 저장하기
if (num[i - 1].text == "NOTICE"):
mongo.check_point_save(name, titles[i].text.strip().split('\n').pop(0))
title = titles[i].text.strip().split("\n").pop(0)
link = 'https://www.bepa.kr' + titles[i].get('href')
date = dates[i].text
if check_point == title:
break
else:
mongo.post_save(name, title, link, date, '')
print('이름: ' + name + '\n제목: ' + title + '\n링크: ' + link + '\n등록일: ' + date + '\n')
except Exception:
message.site_error_push(name)
def bi_scan():
# 창업보육센터 네트워크시스템 사이트
name = '창업보육센터 네트워크시스템'
try:
url = ["http://www.bi.go.kr/board/editView.do?boardID=RECRUIT&frefaceCode=ANNOUNCE&boardVO.postSeq=",
"&boardVO.registDate=", "&boardVO.viewFlag=view"]
# 신청가능 사업 공지
req = requests.get('http://www.bi.go.kr/board/list.do?boardID=RECRUIT&frefaceCode=ANNOUNCE')
html = req.text
soup = BeautifulSoup(html, 'html.parser')
# selector 로 데이터가저오기
titles = soup.select('td > a')
dates = soup.select('tr > td:nth-child(5)')
# 체크포인트 불러오기, 저장하기
check_point = mongo.check_point_read(name)['title']
mongo.check_point_save(name, titles[0].text.strip())
# 데이터 변수로 받아서 txt 저장
for i in range(len(titles)):
title = titles[i].text.strip()
params = re.findall("\d+", titles[i].get('href'))
link = url[0] + params[0] + url[1] + params[1] + url[2]
date = dates[i].text
try:
sdate = date.split(" ~ ").pop(0)
edate = date.split(" ~ ").pop(1)
except Exception: # 상시모집인 경우
sdate = date
edate = ''
if check_point == title:
break
else:
mongo.post_save(name, title, link, sdate, edate)
print('이름: ' + name + '\n제목: ' + title + '\n링크: ' + link + '\n신청기간: ' + date + '\n')
except Exception:
message.site_error_push(name)
def kised_scan():
# 창업진흥원 사이트
name = '창업진흥원'
try:
# 신청가능 사업 공지
req = requests.get('https://www.kised.or.kr/not/notice2.asp')
req.encoding = 'euc-kr'
html = req.text
soup = BeautifulSoup(html, 'html.parser')
# selector 로 데이터가저오기
titles = soup.select('td > a')
dates = soup.select('tr > td:nth-child(4)')
# 체크포인트 불러오기, 저장하기
check_point = mongo.check_point_read(name)['title']
mongo.check_point_save(name, titles[0].text.strip())
# 데이터 변수로 받아서 txt 저장
for i in range(len(titles)):
title = titles[i].text.strip()
link = titles[i].get('href')
date = dates[i].text
if check_point == title:
break
else:
mongo.post_save(name, title, link, date, '')
print('이름: ' + name + '\n제목: ' + title + '\n링크: ' + link + '\n등록일: ' + date + '\n')
except Exception:
message.site_error_push(name)
def busanit_scan():
try:
for j in range(2):
names = ['부산정보산업진흥원_공지사항', '부산정보산업진흥원_사업공고']
urls = ['http://busanit.or.kr/board/list.asp?bcode=notice_e',
'http://busanit.or.kr/board/list.asp?bcode=notice']
# 신청가능 사업 공지
req = requests.get(urls[j])
req.encoding = 'utf-8'
html = req.text
soup = BeautifulSoup(html, 'html.parser')
# selector 로 데이터가저오기
titles = soup.select('td > a')
dates = soup.select('tr > td:nth-child(3)')
# 체크포인트 불러오기, 저장하기
check_point = mongo.check_point_read(names[j])['title']
mongo.check_point_save(names[j], titles[0].text.strip())
# 데이터 변수로 받아서 txt 저장
for i in range(len(titles)):
title = titles[i].text.strip()
link = 'http://busanit.or.kr/board/' + titles[i].get('href')
date = dates[i].text
if check_point == title:
break
else:
mongo.post_save(names[j], title, link, date, '')
print('이름: ' + names[j] + '\n제목: ' + title + '\n링크: ' + link + '\n등록일: ' + date + '\n')
except Exception:
message.site_error_push(name="부산정보산업진흥원")
def motie_scan():
name = '산업통상자원부'
try:
# 신청가능 사업 공지
req = requests.get('http://www.motie.go.kr/motie/ne/Notice/bbs/bbsList.do?bbs_cd_n=83&cate_n=1')
html = req.text
soup = BeautifulSoup(html, 'html.parser')
# selector 로 데이터가저오기
titles = soup.select('div.ellipsis > a')
dates = soup.select('tr > td:nth-child(5)')
# 체크포인트 불러오기, 저장하기
check_point = mongo.check_point_read(name)['title']
mongo.check_point_save(name, titles[0].get('title'))
# 데이터 변수로 받아서 txt 저장
for i in range(len(titles)):
title = titles[i].get('title')
link = "http://www.motie.go.kr/motie/ne/Notice/bbs/"+titles[i].get('href')
date = dates[i].text
if check_point == title:
break
else:
mongo.post_save(name, title, link, date, '')
print('이름: ' + name + '\n제목: ' + title + '\n링크: ' + link + '\n등록일: ' + date + '\n')
except Exception:
message.site_error_push(name)
def seoulstartuphub_scan():
name = '서울창업허브'
try:
# 신청가능 사업 공지
url = 'http://seoulstartuphub.com/policy/supportList.do'
context = ssl._create_unverified_context()
result = urlopen(url, context=context)
soup = BeautifulSoup(result.read(), "html.parser")
# selector 로 데이터가저오기
titles = soup.select('td.left> a')
dates = soup.select('tr > td:nth-child(5)')
# 체크포인트 불러오기, 저장하기
check_point = mongo.check_point_read(name)['title']
mongo.check_point_save(name, titles[0].text.strip())
# 데이터 변수로 받아서 txt 저장
for i in range(len(titles)):
title = titles[i].text.strip()
link = titles[i].get('href').strip()
date = dates[i].text
try:
sdate = date.split(" ~ ").pop(0)
edate = date.split(" ~ ").pop(1)
except Exception: # 상시모집인 경우
sdate = date
edate = ''
sdate = sdate[0:4] + '.' + sdate[4:6] + '.' + sdate[6:8]
edate = edate[0:4] + '.' + edate[4:6] + '.' + edate[6:8]
if check_point == title:
break
else:
mongo.post_save(name, title, link, sdate, edate)
print('이름: ' + name + '\n제목: ' + title + '\n링크: ' + link + '\n신청기간: ' + date + '\n')
except Exception:
message.site_error_push(name)
def koita_scan():
try:
# 한국산업진흥협회
names = ['한국산업진흥협회_공지사항', '한국산업진흥협회_사업공고', '한국산업진흥협회_정부 R&D 사업공고']
urls = ['https://www.koita.or.kr/notice/notice_list.aspx', 'https://www.koita.or.kr/notice/gov_list.aspx?q=1',
'https://www.koita.or.kr/certificate/prnd_board2_list.aspx']
url = ['https://www.koita.or.kr/notice/notice_view.aspx?no=',
'https://www.koita.or.kr/notice/gov_view.aspx?q=1&no=',
'https://www.koita.or.kr/certificate/prnd_board4_view.aspx?no=']
for j in range(3):
# 신청가능 사업 공지
req = requests.get(urls[j])
html = req.text
soup = BeautifulSoup(html, 'html.parser')
# selector 로 데이터가저오기
titles = soup.select('td > a')
dates = soup.select('tr > td:nth-child(5)')
# 체크포인트 불러오기, 저장하기
check_point = mongo.check_point_read(names[j])['title']
mongo.check_point_save(names[j], titles[0].text.strip())
# 데이터 변수로 받아서 txt 저장
for i in range(len(titles)):
title = titles[i].text.strip()
link = url[j] + re.findall("\d+", titles[i].get('href')).pop()
date = dates[i].text
if check_point == title:
break
else:
mongo.post_save(names[j], title, link, date, '')
print('이름: ' + names[j] + '\n제목: ' + title + '\n링크: ' + link + '\n등록일: ' + date + '\n')
except Exception:
message.site_error_push(name="한국산업진훙협회")
def kisdi_scan():
# 정보통신정책연구원 - 링크 수정
name = '정보통신정책연구원'
try:
# 신청가능 사업 공지
req = requests.get(
'http://www.kisdi.re.kr/kisdi/fp/kr/board/listSingleBoard.do?cmd=listSingleBoard&sBoardId=GPK_NOTICE&sEntDate=&eEntDate=&searchValue=&listScale=10&curPage=1&ordTxt=M001005')
html = req.text
soup = BeautifulSoup(html, 'html.parser')
# selector 로 데이터가저오기
titles = soup.select('td.board-title > a')
dates = soup.select('tr > td:nth-child(4)')
# 체크포인트 불러오기, 저장하기
mongo.check_point_read(name)
check_point = mongo.check_point_read(name)['title']
mongo.check_point_save(name, titles[0].text.strip())
# 데이터 변수로 받아서 txt 저장
for i in range(len(titles)):
title = titles[i].text.strip()
tmp = titles[i].get('href')
link = 'http://www.kisdi.re.kr/' + "".join(tmp.split())
date = dates[i].text.strip()
if check_point == title:
break
else:
mongo.post_save(name, title, link, date, '')
print('이름: ' + name + '\n제목: ' + title + '\n링크: ' + link + '\n등록일: ' + date + '\n')
except Exception:
message.site_error_push(name)
def kai_scan():
# 지능정보산업협회
name = '지능정보산업협회'
try:
# 신청가능 사업 공지
req = requests.get('http://www.k-ai.or.kr/kr/information/notice.php')
req.encoding = 'utf-8'
html = req.text
soup = BeautifulSoup(html, 'html.parser')
# selector 로 데이터가저오기
top_count = soup.select('span.notice-icon')
titles = soup.select('td > a')
dates = soup.select('tr > td:nth-child(3)')
# 체크포인트 불러오기, 저장하기
check_point = mongo.check_point_read(name)['title']
# top_count 공지갯수를 세서 공지를 제외하고 check_point를 저장
mongo.check_point_save(name, titles[len(top_count)].text.strip())
# 데이터 변수로 받아서 txt 저장
for i in range(len(titles)):
title = titles[i].text.strip()
if check_point != title:
link = 'http://www.k-ai.or.kr' + titles[i].get('href')
date = dates[i].text
try:
edate = date.split("~").pop(1)
sdate = date.split("~").pop(0)
# 형식이 다른경우
except Exception:
sdate = date
edate = ''
# 상단고정 공지때문에 저장된건 중복 걸러주기
if mongo.is_saved(title) is None:
mongo.post_save(name, title, link, sdate, edate)
print('이름: ' + name + '\n제목:' + title + '\n링크: ' + link + '\n날짜: ' + date + '\n')
else:
break
except Exception:
message.site_error_push(name)
def busan_scan():
# 부산광역시 사이트
name = '부산광역시'
try:
# 신청가능 사업 공지
req = requests.get('http://www.busan.go.kr/nbgosi')
html = req.text
soup = BeautifulSoup(html, 'html.parser')
# selector 로 데이터가저오기
titles = soup.select('td > a')
dates = soup.select('tr > td:nth-child(4)')
# 체크포인트 불러오기, 저장하기
check_point = mongo.check_point_read(name)['title']
mongo.check_point_save(name, titles[0].text.strip())
# 데이터 변수로 받아서 txt 저장
for i in range(len(titles)):
title = titles[i].text.strip()
if check_point != title:
link = 'http://www.busan.go.kr' + titles[i].get('href')
date = dates[i].text.strip()
mongo.post_save(name, title, link, date, '')
print('이름: ' + name + '\n제목: ' + title + '\n링크: ' + link + '\n등록일: ' + date + '\n')
else:
break
except Exception:
message.site_error_push(name)
def koraia_scan():
name = '한국인공지능협회'
try:
# 신청가능 사업 공지
req = requests.get('https://www.koraia.org/board/index.html?id=bizalim&page=1')
html = req.text
soup = BeautifulSoup(html, 'html.parser')
# selector 로 데이터가저오기
titles = soup.select('td.wz_subject > a')
dates = soup.select('tr > td:nth-child(3)')
dates.pop(0)
dates.pop(0)
# 체크포인트 불러오기, 저장하기
check_point = mongo.check_point_read(name)['title']
mongo.check_point_save(name, titles[0].text.strip())
# 데이터 변수로 받아서 txt 저장
for i in range(len(titles)):
title = titles[i].text.strip()
if check_point != title:
link = 'https://www.koraia.org/board/' + titles[i].get('href')
date = dates[i].text
mongo.post_save(name, title, link, date, '')
print('이름: ' + name + '\n제목: ' + title + '\n링크: ' + link + '\n등록일: ' + date + '\n')
else:
break
except Exception:
message.site_error_push(name)
def ideamaru_scan():
name = '아이디어마루'
try:
# 신청가능 사업 공지
req = requests.get('https://www.ideamaru.or.kr/business/sch/notice')
html = req.text
soup = BeautifulSoup(html, 'html.parser')
# selector 로 데이터가저오기
titles = soup.select('td > span > a')
dates = soup.select('tr > td:nth-child(4)')
# 체크포인트 불러오기, 저장하기
check_point = mongo.check_point_read(name)['title']
mongo.check_point_save(name, titles[0].text.strip())
# 데이터 변수로 받아서 txt 저장
for i in range(len(titles)):
title = titles[i].text.strip()
if check_point != title:
param = re.findall("\d+", titles[i].get('href'))
link = 'https://www.ideamaru.or.kr/business/sch/notice/view?ATCL_NUM=' + param[0]
date = dates[i].text
mongo.post_save(name, title, link, date, '')
print('이름: ' + name + '\n제목: ' + title + '\n링크: ' + link + '\n등록일: ' + date + '\n')
else:
break
except Exception:
message.site_error_push(name)
def btp_scan():
try:
names = ['부산테크노파크_사업공고', '부산테크노파크_공지사항']
urls = ['http://www.btp.or.kr/index.php?action=BD0000M&pagecode=P000000010&language=KR',
'http://www.btp.or.kr/index.php?action=BD0000M&pagecode=P000000013&language=KR']
for j in range(2):
for pageindex in range(1, 3): # 1-2페이지까지 돌림
# 신청가능 사업 공지
req = requests.get(urls[j]+"&pageIndex="+str(pageindex))
req.encoding = 'utf-8'
html = req.text
soup = BeautifulSoup(html, 'html.parser')
# selector 로 데이터가저오기
titles = soup.select(' tr > td.ui-pleft20 > a')
if j == 0:
dates = soup.select('tr > td:nth-child(3)')
else:
dates = soup.select('tr > td:nth-child(4)')
# 데이터 변수로 받아서 txt 저장
for i in range(len(titles)):
title = titles[i].text.strip()
if mongo.is_saved(title) is None:
param = re.findall("\d+", titles[i].get('href'))
link = urls[j] + '&command=View&idx=' + param[0]
date = dates[i].text.split("(").pop(0).strip()
try:
edate = date.split("~").pop(1)
sdate = date.split("~").pop(0)
# 형식이 다른경우
except Exception:
sdate = ''
edate = date
# 상단고정 공지때문에 저장된건 중복 걸러주기
mongo.post_save(names[j], title, link, sdate, edate)
print('이름: ' + names[j]+ '\n제목:' + title + '\n링크: ' + link + '\n날짜: ' + sdate + edate + '\n')
except Exception:
message.site_error_push(name="부산테크노파트")
def sbsc_scan():
# 서울시 지원사업
name = '서울시 지원사업'
try:
urls = ['https://sbsc.seoul.go.kr/fe/support/seoul/NR_view.do?bbsCd=1&bbsSeq=','¤tPage=1&searchVals=&bbsGrpCds_all=on&orgCd=']
req = requests.get('https://sbsc.seoul.go.kr/fe/support/seoul/NR_list.do?bbsCd=1')
html = req.text
soup = BeautifulSoup(html, 'html.parser')
# selector 로 데이터가저오기
titles = soup.select('td > a')
dates = soup.select('tr > td:nth-child(4)')
# 체크포인트 불러오기, 저장하기
check_point = mongo.check_point_read(name)['title']
mongo.check_point_save(name, titles[0].text.strip())
# 데이터 변수로 받아서 txt 저장
for i in range(len(titles)):
title = titles[i].text.strip()
seq = re.findall("\d+", titles[i].get('onclick'))
link = urls[0] + seq[0] + urls[1]
date = dates[i].text.strip()
sdate = date[0:10]
edate = date[10:20]
if check_point == title:
break
else:
mongo.post_save(name, title, link, sdate, edate)
print('이름: ' + name + '\n제목: ' + title + '\n링크: ' + link + '\n신청기간: ' + sdate + ' ~ ' + edate +'\n')
# 중앙정부 지원사업
name = '중앙정부 지원사업'
req = requests.get('https://sbsc.seoul.go.kr/fe/support/bizinfo/NR_list.do')
html = req.text
soup = BeautifulSoup(html, 'html.parser')