Home > OS >  Python - Split in one iteration
Python - Split in one iteration

Time:12-09

Why are functions often not available like this SPLIT in the final image?
How can I use split in this iteration?

enter image description here

soup = BeautifulSoup(teste, "html.parser")

Vagas = soup.find_all(title="Vaga disponível.")



temp=[]
for i in Vagas:
    on_click = i.get('onclick')
    temp.append(on_click)

achado2 = temp.split('\'')[1::6]

print(temp)

CodePudding user response:

Here you defined temp as a list. It is actually already split into a list of elements, so .split() can not be applied on a list.
split() may be applied on a string to make from it a list of substrings.

CodePudding user response:

Solved it by turning my list into a string and then using split on it again.

temp=[]
for i in Vagas:
    on_click = i.get('onclick')
    temp.append(on_click)


texto = str(temp)

achado2 = texto.split('\'')[1::6]
  • Related