私はスクリプトを書くためにpythonを使って、html内の特定のパターン化されたテキストを削除しようとしました。しかし、私のコードは動作していないようです。Pythonを使ってhtmlからパターン化されたテキストを削除する
import os, re
cwd = os.getcwd()
print ('Now you are at this directory: \n' + cwd)
# find files that have an extension with HTML
Files = os.listdir(cwd)
print Files
def func(file):
for file in os.listdir(cwd):
if file.endswith('.html'):
for line in open(file):
re.sub(r'<strong>.*?<\/strong>', '', line)
# I feel the above line has some problems
func(file)
ありがとうございます!
ありがとうThierry、私は間違いなくbeautifulsoupをチェックします!正規表現の場合、私は両方のパターンを試しましたが、どちらも動作しません...オリジナルのスクリプトを使用して、一致するテキストを印刷しようとすると、実際には正しくなります。私は一致した文字列を置き換えることを妨げるコードでどの部分が間違っているのか分かりません... – Penny