검사
기한은 10월 20일.
자료import json,sys,platform
from html.parser import HTMLParser
import re
class Main(HTMLParser):
def __init__(self):super().__init__();self.depth=0;self.skip=0;self.text=[];self.links=[];self.headings=[];self.mainCount=0;self.verbatim=False
def handle_starttag(self,t,a):
if t=='main':self.depth+=1;self.mainCount+=1
if self.depth and t in ['pre','code']:self.verbatim=True
if self.depth and t in ['script','style','nav','aside']:self.skip+=1
if self.depth and not self.skip and t=='a':self.links.append(dict(a).get('href',''))
def handle_endtag(self,t):
if self.depth and t in ['script','style','nav','aside']:self.skip-=1
if t=='main':self.depth-=1
def handle_data(self,v):
if self.depth and not self.skip:self.text.append(v)
def extract(s):
p=Main();p.feed(s);text=re.sub(r'\s+',' ',' '.join(p.text)).strip();reasons=[]
if p.mainCount!=1:reasons.append('main-count-must-be-one')
if not text:reasons.append('empty-main-text')
if p.depth!=0 or p.skip!=0:reasons.append('unbalanced-tracked-tags')
if p.verbatim:reasons.append('verbatim-policy-required')
return {'text':text,'links':p.links,'mainCount':p.mainCount,'comparisonReady':not reasons,'holdReasons':reasons}
def compare(before,after):
left=extract(before);right=extract(after);ready=left['comparisonReady'] and right['comparisonReady']
return {'comparisonStatus':'compared' if ready else 'hold-extraction','textEqual':left['text']==right['text'] if ready else None,'linksEqual':left['links']==right['links'] if ready else None,'before':left,'after':right}
a=' 기한은 10월 20일. 기한은 10월 20일.검사
검사
a b
a b