-2
text = '<span>geldi <span data-jid="@c.us" data-display="Gerçek Ege" class="matched-mention i0jNr selectable-text select-all copyable-text" data-plain-text="@Gerçek Ege" data-app-text-template="​905386782644@c.us​"><span class="at-symbol">@</span><span dir="ltr">Gerçek Ege</span></span></span>'
text1 = text.replace("<span>"," "), text.replace("<span"," "), text.replace(">"," "), text.replace("</span>"," ")
text1= ''.join(text1)
tex2= text1.rsplit(" ")
for i in tex2:
    if "data-jid="or"data-display="or"class="or"i0jNr"or"selectable-text"or"select-all"or"copyable-text"or"data-plain-text="or"data-app-text-template="or"dir="or"</span>" in i:
        tex2.remove(i)
print(text1)
print(tex2)

i tryed this but it didnt worked how can i do this

  • There are several problems with this code and it's not clear which one you are asking about. – mkrieger1 Sep 02 '22 at 14:20
  • yeah im not profeesinoal as you can see but im trying to delete items which includes that words in list – BERKAY ayar Sep 02 '22 at 14:21
  • It looks like you're trying to remove the tags from an HTML string, and this is definitely the wrong way to do it. See here: https://stackoverflow.com/questions/753052/strip-html-from-strings-in-python – Izkata Sep 02 '22 at 14:22

1 Answers1

0

It is not advisable to remove item in a list when doing a loop. It is better to create a new list and append items into that new list (tex3).

text = '<span>geldi <span data-jid="@c.us" data-display="Gerçek Ege" class="matched-mention i0jNr selectable-text select-all copyable-text" data-plain-text="@Gerçek Ege" data-app-text-template="​905386782644@c.us​"><span class="at-symbol">@</span><span dir="ltr">Gerçek Ege</span></span></span>'
text1 = text.replace("<span>"," "), text.replace("<span"," "), text.replace(">"," "), text.replace("</span>"," ")
text1= ''.join(text1)
tex2= text1.rsplit(" ")
tex3=list()
for i in tex2:
    if "data-jid="or"data-display="or"class="or"i0jNr"or"selectable-text"or"select-all"or"copyable-text"or"data-plain-text="or"data-app-text-template="or"dir="or"</span>" in i:
        continue
    else:
        tex3.append(i)
print(text1)
print(tex3)
jose_bacoy
  • 12,227
  • 1
  • 20
  • 38