# -*- 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) KOGLNAME=re.compile(r'(open(?:type|code)\d|opentype_\w+|ccl_\w+|kogl|nuri|gongu|공공누리)', re.I) tests=[('우리민요반주(2유형)','http://www.igbf.kr/gugak_web/?sub_num=849'), ('보도자료(1유형,AI)','http://www.igbf.kr/gugak_web/?sub_num=764'), ('국악교육자료','http://www.igbf.kr/gugak_web/?sub_num=770'), ('편성표','http://www.igbf.kr/gugak_web/?sub_num=786'), ('국악방송소개','http://www.igbf.kr/gugak_web/?sub_num=754')] for nm,u in tests: h=g(u) koglimgs=[s for s in IMG.findall(h) if KOGLNAME.search(s)] print('%s:'%nm) print(' kogl img:', koglimgs[:6]) # 보도자료는 게시판 -> 상세 확인 if 'board' in u or 'sub_num=764' in u: pass