S
seaspeak
I need to replace all tag <b> with <span> after â– . But the result from below is 'â– <span style="REPLACE">D</span> / <font></font>'
Can you explain what I did wrong, please.
s = 'â– <b>A</b> <b>B</b> <b>C</b> <b>D</b> / <font></font>'
soup = BeautifulSoup(s)
for i in soup.find_all(text='â– '):
tag = soup.new_tag('span')
tag['style'] = 'REPLACE'
for ii in i.find_next_siblings():
if ii.name=='font' or str(ii).lstrip('')[0:1]=='/':
break
else:
if ii.name=='b':
tag.string=ii.string
print(ii.replace_with(tag))
print(soup)
Can you explain what I did wrong, please.
s = 'â– <b>A</b> <b>B</b> <b>C</b> <b>D</b> / <font></font>'
soup = BeautifulSoup(s)
for i in soup.find_all(text='â– '):
tag = soup.new_tag('span')
tag['style'] = 'REPLACE'
for ii in i.find_next_siblings():
if ii.name=='font' or str(ii).lstrip('')[0:1]=='/':
break
else:
if ii.name=='b':
tag.string=ii.string
print(ii.replace_with(tag))
print(soup)