-
好好看呢訥訥
查看全部 -
jieba分詞主要功能
查看全部 -
jieba分詞核心算法簡(jiǎn)介
查看全部 -
jieba三種分詞模式與特點(diǎn)
查看全部 -
jieba分詞模式、核心算法
查看全部 -
""" Description:正則清洗HTML數(shù)據(jù) Author: Prompt:?code?in?python3?env """ """ ???re.I???使匹配對(duì)大小寫不敏感 ???re.L???做本地化識(shí)別(locale-aware)匹配 ???re.M???多行匹配,影響^(開頭)和$(結(jié)尾) ???re.S???匹配包含換行在內(nèi)的所有字符 ???re.U???根據(jù)Unicode字符集解析字符,這個(gè)標(biāo)志影響?\w,?\W,?\b,?\B ???re.X???該標(biāo)志通過給予你更靈活的格式以便你將正則表達(dá)式寫得更加 """ import?re #?處理HTML標(biāo)簽文本 #?@param?htmlstr?html字符串 def?filter_tags(htmlstr): ???#?過濾doc_type ???htmlstr?=?'?'.join(htmlstr.split()) ???re_doctype?=?re.compile(r'<!DOCTYPE?.*?>',?re.S) ???res?=?re_doctype.sub('',?htmlstr) ???""" ???#?過濾CDATA ???re_cdata?=?re.compile(?r'//<!CDATA\[[?>]?//\]?>',?re.I) ???res?=?re_cdata.sub('',?res) ???#?Script ???re_script?=?re.compile('<\s*script[^>]*>[^<]*<\s*/\s*script\s*>',?re.I) ???res?=?re_script.sub('',?res) ???#?注釋 ???re_script?=?re.compile('<!--.*?-->',?0) ???res?=?re_script.sub('',?res) ???#?換行符 ???re_br?=?re.compile('<br\n*?/?>') ???res?=?re_br.sub('\n',?res) ???#?HTML?標(biāo)簽 ???re_lable?=?re.compile('</?\w[^>]*>') ???res?=?re_lable.sub('',?res) ???#?轉(zhuǎn)義字符 ???re_esc?=?re.compile('&.*?;') ???res?=?re_esc.sub('',?res) ???#?空格處理 ???re_blank?=?re.compile('\s+')?#?\s包含?\t?\n?\r?\f?\v ???res?=?re_blank.sub('?',?res) ???#?超鏈接處理 ???re_http?=?re.compile(r'(http://.+.html)') ???res?=?re_http.sub('?',?res) ???""" ???#?return?res ???re_mate?=?[ ??????(r'<!DOCTYPE?.*?>',?re.S), ??????(r'//<!CDATA\[[?>]?//\]?>',?re.I), ??????(r'<\s*script[^>]*>[^<]*<\s*/\s*script\s*>',?re.I), ??????(r'<!--.*?-->',?re.I), ??????(r'<br\n*?/?>',?), ??????(r'</?\w[^>]*>',?), ??????(r'&.*?;',?), ??????(r'\s+',?), ??????(r'(http://.+.html)',?), ???] ???d?=?lambda?pattern,?flags=0:?re.compile(pattern,?flags) ???for?re_type?in?re_mate: ??????re_type?=?d(*re_type) ??????res?=?re_type.sub('?',?res) ???return?res def?read_file(read_path): ???str_doc?=?'' ???with?open(read_path,?'r',?encoding='utf-8')?as?f: ??????str_doc?=?f.read() ???return?str_doc if?__name__?==?'__main__': ???str_doc?=?read_file(r're.html') ???res?=?filter_tags(str_doc) ????print(res) #???with?open(r'../data/html/test.html',?'w',?encoding='utf-8')?as?f: #??????f.write(res) #???print('No?Exception')?#?我是通過另一個(gè)編輯器進(jìn)行打開預(yù)覽的
這是我做的筆記,和老師的有些不一樣但是效果一樣的
查看全部 -
Formit查看全部
-
ccccxxqaa查看全部
-
12233699988999988636999999999999999999999999999999999999999999999999999999....99..966699988558899699999999999966696663322885244856666699636999663366966668556666666445266699666666666336666666666666666666666666666666666666666666333699669966333333333333333333333333333333333333333333333366963585255772369963699999999996362885888669999669999996699999966699669966999852885244666999999999636999636995588566996669996查看全部
-
學(xué)習(xí)要點(diǎn)。
查看全部 -
本節(jié)課程要點(diǎn)
查看全部 -
本節(jié)課程要點(diǎn)
查看全部 -
哈哈哈查看全部
-
ccvbnb查看全部
-
猜猜猜查看全部
舉報(bào)
0/150
提交
取消