【发布时间】:2015-09-14 14:42:54
【问题描述】:
........<p style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; text-indent:0px;">textHere
<span style=" font-family:'Noto Sans';">ABC</span></p>
<p style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; text-indent:0px;"><span style=" font.......
我有一个像上面这样的 HTML。我需要
- 在“Noto Sans”字体系列中查找所有内容(它们总是在 span 标签内)
- 在不更改其余代码的情况下替换它们(A 为 X,B 为 Y 等...)
我试过的是这个,但不能正常工作。
from bs4 import BeautifulSoup
source_code = """.....<span style=" font-family:'Noto Sans';">ABC</span></p>......""
soup = BeautifulSoup(source_code, "lxml")
for re in soup.findAll('font', 'face' = "Noto Sans"):
print (re.replace("A", "X"))
有什么想法吗?
【问题讨论】:
标签: python html beautifulsoup html-parsing