728x90
반응형
a_ict_word라는 클래스 이름으로 된 모든 span 요소를 제거하여, 문장 내에서 특정 단어를 강조하는 역할로 삽입된 요소를 제거하여, 끊김 없는 문장을 추출하는 프로그램입니다. 다소 규칙기반적인 사항으로 작성되었습니다.
if ( document.querySelectorAll('.a_ict_word') != undefined) {
const spanElms = document.querySelectorAll('.a_ict_word');
if( spanElms.length > 0 ) {
var parentIDArray = new Array( spanElms.length );
var parentID = 0;
parentIDArray[0] = parentID;
previousParent = spanElms[0].parentNode;
for( ii =1; ii<spanElms.length; ii++){
currentParent = spanElms[ii].parentNode;
parentIDArray[ii] = parentID;
if( currentParent != previousParent){
previousParent = currentParent;
parentIDArray[ii] = ++parentID;
}
}
}
jj=0;
for( jj = 0; jj<spanElms.length; jj++){
if( spanElms[jj].previousSibling != undefined && spanElms[jj].nextSibling != undefined && spanElms[jj].childNodes[0] != undefined ){
makeSentence = spanElms[jj].previousSibling.textContent.replace(/^\s+|\s+$/g,"") + " "+ spanElms[jj].childNodes[0].textContent.replace(/^\s+|\s+$/g,"") + spanElms[jj].nextSibling.textContent.replace(/^\s+|\s+$/g,"");
spanElms[jj].previousSibling.textContent = makeSentence;
spanElms[jj].childNodes[0].textContent ="";
spanElms[jj].nextSibling.textContent="";
if( spanElms[jj].nextSibling && spanElms[jj].nextSibling.nextSibling && spanElms[jj].nextSibling.nextSibling.textContent){
if( spanElms[jj].nextSibling.nextSibling.textContent.indexOf('<br>') || spanElms[jj].nextSibling.nextSibling.textContent.indexOf('</p>' ) || spanElms[jj].nextSibling.nextSibling.textContent.indexOf("''" ) || spanElms[jj].nextSibling.nextSibling.textContent.length == 0 ){
continue;
}
if( (spanElms[jj].nextSibling.nextSibling.tagName) && (spanElms[jj].nextSibling.nextSibling.tagName == "BR") )
continue;
}
if( spanElms[jj].nextSibling.nextSibling == undefined )
continue;
for( kk=jj ; kk <spanElms.length; kk++ ){
if( parentIDArray[ jj ] != parentIDArray[ jj + kk ] )
break;
if( spanElms[jj + kk ] && spanElms[jj + kk ].previousElementSibling ){
if( spanElms[jj + kk ].previousElementSibling.nodeName == 'BR' )
break;
}
if( spanElms[jj + kk ] && spanElms[jj + kk ].nextElementSibling ) {
if( spanElms[jj + kk ].nextElementSibling.className === 'a_ict_word'){
spanElms[jj ].previousSibling.textContent += spanElms[jj + kk ].nextElementSibling.childNodes[0].textContent;
spanElms[jj + kk ].nextElementSibling.childNodes[0].textContent="";
spanElms[jj ].previousSibling.textContent += spanElms[jj + kk ].nextElementSibling.nextSibling.textContent;
spanElms[jj + kk ].nextElementSibling.nextSibling.textContent ="";
}
}
}
}
else if( spanElms[jj].previousSibling == undefined && spanElms[jj].nextSibling != undefined ){
makeSentence = spanElms[jj].childNodes[0].textContent.replace(/^\s+|\s+$/g,"") + spanElms[jj].nextSibling.textContent.replace(/^\s+|\s+$/g,"");
spanElms[jj].childNodes[0].textContent = "";
spanElms[jj].nextSibling.textContent=makeSentence;
}
}
}
728x90
반응형
'프로그램언어(JAVA , Python)' 카테고리의 다른 글
spring boot : 어플리케이션 구조, Layered 구조 예시( 개발 순서 및 결과물 ) (0) | 2023.06.29 |
---|---|
[Spring-boot:Swagger] Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException (0) | 2023.06.27 |
[Apache 웹서버] mod_rewrite 예제 (0) | 2023.03.03 |
[HTML] Google 검색( 크롤링/인덱싱 ) 유도, <a> URL link & 숨기기 (0) | 2023.02.14 |
[Python] 로그파일 사용자정의함수에 의한 로그로테이션 및 파일 사용자명/그룹명 변경 (0) | 2022.01.21 |