Tag and string mixed find-and-replace using BeautifulSoup in python
问题 How do you use the BeautifulSoup .replace_with() without having something like sharp brackets being converted to > thing after a str() string conversion find-and-replace process? Python code from bs4 import BeautifulSoup with open("../dicttest.txt", "r", encoding="utf-8") as f: full_text = f.read() parse_1 = BeautifulSoup(full_text, "html.parser") for line in parse_1.find_all("grace", "AllExamples"): match = str(line).replace(";</i> <b>", ";</i><br> <b>") line.replace_with(match) print(parse