有很多模塊,例如lxml,Beautiful湯,nltk和pyenchant,可以正確過濾出正確的英語單詞。但是,然后是什么最干凈的最短方法,例如html2text,如果也可以取消降價促銷(我寫的時候,右邊有很多類似的問題)可能有一個通用的正則表達(dá)式可以刪除所有的html。標(biāo)簽?def word_parse(f): raw = nltk.clean_html(f) #f = url.content here, from "requests" module regex = r'[a-zA-Z]+' # | ^[a-zA-Z]+\b' match = re.compile(regex) ls = [] for line in raw.split(): for mat in line.split(): try: v = match.match(mat).group() map(ls.append, v.split()) except AttributeError, e: pass有人可以建議一些好的代碼片段嗎?有人可以在這里建議更簡潔,更優(yōu)化的代碼嗎?
Python:從html搜索和收集文本字符串的更好方法。剝離減價,標(biāo)簽等
ibeautiful
2021-03-16 09:09:18