# -*- coding: utf-8 -*- import urllib.request, ssl, re, http.cookiejar ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE cj=http.cookiejar.CookieJar(); op=urllib.request.build_opener(urllib.request.HTTPSHandler(context=ctx),urllib.request.HTTPCookieProcessor(cj)) op.addheaders=[('User-Agent','Mozilla/5.0')] def fixdom(u): return str(u).replace('https://new.igbf.kr','http://www.igbf.kr') def g(u): return op.open(fixdom(u),timeout=20).read().decode('utf-8','replace') IMG=re.compile(r']+src="([^"]+)"', re.I) # 우리민요반주 페이지 h=g('http://www.igbf.kr/gugak_web/?sub_num=849') print('=== 우리민요반주(849) 전 img (파일명) ===') for s in IMG.findall(h): fn=s.split('/')[-1] if not re.search(r'(logo|ico_|chn_|onair|btn|menu|_sk|_kt|_lg|mmtr)', fn, re.I): print(' ',fn) print('공공누리/유형 텍스트:', re.findall(r'(공공누리[^<]{0,20}|제\s*\d\s*유형|[Kk][Oo][Gg][Ll])', h)[:6]) # 보도자료 게시판 상세 hb=g('http://www.igbf.kr/gugak_web/?sub_num=764') bid=re.search(r'(idx|bIdx|seq|num)=(\d+)', hb) # 보도자료 list url 추출 print('\n=== 보도자료(764) list view 링크 ===') print(' bIdx:', re.findall(r'bIdx=(\d+)', hb)[:3], '| board.jsp:', re.findall(r'(\w+board\w*\.jsp)', hb)[:3])