Reputation: 17
I would like to know the function to transform a list / webelement variable into .txt with the code below I can only read the file on my console en.txt but not save it on my pc.
recuperation_nom = driver.find_elements_by_class_name("title-3")
for resultat_nom in recuperation_nom:
print(resultat_nom.text)
Upvotes: 0
Views: 172
Reputation: 2692
Just open .txt
file in access mode 'a'
, then write each line into it.
recuperation_nom = driver.find_elements_by_class_name("title-3")
with open('output.txt', 'a') as f:
f.truncate(0)
for resultat_nom in recuperation_nom:
f.write(f"{resultat_nom.text}\n")
Upvotes: 1