공공기관2 작업 중. _temp 몽타주(재생성가능)는 제외. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
38 lines
1.8 KiB
Python
38 lines
1.8 KiB
Python
import openpyxl, requests, sys, re
|
|
from bs4 import BeautifulSoup
|
|
import urllib3
|
|
urllib3.disable_warnings()
|
|
sys.stdout.reconfigure(encoding='utf-8')
|
|
p = r'D:\01.프로젝트\DB수집\작업파일\광역_사이트맵\충청남도\9.서천군\충청남도_서천군.xlsx'
|
|
wb = openpyxl.load_workbook(p); ws = wb.active
|
|
H = {'User-Agent':'Mozilla/5.0'}
|
|
def get(u):
|
|
r = requests.get(u, headers=H, timeout=20, verify=False); r.encoding=r.apparent_encoding or 'utf-8'; return r.text
|
|
def norm(u):
|
|
if not u: return ''
|
|
u = u.split('#')[0].rstrip('/')
|
|
u = re.sub(r'^https?://www\.seocheon\.go\.kr','',u)
|
|
return u
|
|
# collect all sheet urls
|
|
sheet_urls=set()
|
|
for r in range(3, ws.max_row+1):
|
|
c=ws.cell(r,11)
|
|
u=c.hyperlink.target if c.hyperlink else (c.value if isinstance(c.value,str) else '')
|
|
if u: sheet_urls.add(norm(u))
|
|
rows=[17,22,25,35,48,57,70,78,94,97,102,104,107,134,135,136,168,170,171,176,183,193,199,200,217,219,222,227,235,237,238,239,240,250,268]
|
|
print('sheet has', len(sheet_urls), 'urls')
|
|
for r in rows:
|
|
cell=ws.cell(r,11); url=cell.hyperlink.target if cell.hyperlink else cell.value
|
|
label=ws.cell(r,7).value or ws.cell(r,6).value or ''
|
|
try: soup=BeautifulSoup(get(url),'html.parser')
|
|
except Exception as e: print(f'R{r} ERR {e}'); continue
|
|
ul=soup.select_one('ul.basic_tab')
|
|
if not ul: continue
|
|
tabs=[(' '.join(li.get_text().split())[:12],(li.find('a').get('href') if li.find('a') else '')) for li in ul.select('li')]
|
|
miss=[t for t,h in tabs if norm(h) and norm(h) not in sheet_urls]
|
|
covered=len(tabs)-len(miss)
|
|
tag='ALL-COVERED' if not miss else ('NONE' if covered<=1 else 'PARTIAL')
|
|
print(f'R{r:>3} {str(label)[:16]:16} tabs={len(tabs)} covered={covered} missing={len(miss)} [{tag}]')
|
|
if miss:
|
|
print(' missing:', ', '.join(miss[:8]))
|