長話短說,我試圖用美麗的湯用強烈的標籤取代b標籤。 湯需要一些投入,包括美麗的湯find_all包裝在一起,而不是單獨的
<b>Words:</b> attributes
<b>Other Words:</b> other attributes
我有以下python3代碼:
strong_tag = soup.new_tag("strong")
if(soup.find('b')):
for b_tag in soup.find_all('b'):
b_tag.wrap(strong_tag)
此輸出
attributes
<strong><b>Words:</b><b>Other Words:</b></strong> other attributes
,而不是
<strong><b>Words:</b></strong> attributes
<strong><b>Other Words:</b></strong> other attributes
我如何 解決這個問題?
我假設一旦我能解決這個問題,我可以從b標籤中提取()內容,只留下強標籤。