第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

正在回答

2 回答

"""
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)

???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'../data/html/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ù)覽的

這是我的筆記

1 回復(fù) 有任何疑惑可以回復(fù)我~
#1

weixin_慕尼黑7100639

你好,這段代碼下面的re_mate報(bào)錯(cuò)(未定義) for re_type in re_mate: re_type = d(*re_type) res = re_type.sub(' ', res) return res
2022-07-07 回復(fù) 有任何疑惑可以回復(fù)我~

https://github.com/bainingchao/DataProcess


1 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

源碼能分享下嗎

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)