Skip to content
조회 수 3121 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

python html tag 제거 경로 금지 문자 제거

 

 

from pytube import YouTube
 
# 경로 금지 문자 제거, HTML문자 제거
import re
def filename_remover(string):
        cleaner = re.compile('<.*?>|&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-f]{1,6});') #<tag>, &nbsp 등등 제거
        string = re.sub(cleaner, '', string)
        while(string[-1] == '.'):
            string = string[:-1] #끝에 . 제거 ex) test... -> test
        non_directory_letter = ['/', ':', '*', '?', '<', '>', '|'] #경로 금지 문자열 제거
        for str_ in non_directory_letter:
                if str_ in string:
                        string = string.replace(str_, "")
        return string
 
url = 'https://www.youtube.com/watch?v=FbVeMmO6G60&t=1s'
yt = YouTube(url)
 
caption = yt.captions.all()[0]  # 첫번째 자막 선택
caption_xml=caption.xml_captions # html문서로 변환
re_string=filename_remover(caption_xml)
print(re_string)

 

 

로그인 후 댓글쓰기가 가능합니다.

?

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소