我想知道通过以下代码将列表/ webelement变量转换为.txt的函数。我只能在我的控制台en.txt上读取文件,而不能将其保存在我的pc上。
recuperation_nom = driver.find_elements_by_class_name("title-3")
for resultat_nom in recuperation_nom:
print(resultat_nom.text)发布于 2021-03-01 20:42:15
只需在访问模式'a'中打开.txt文件,然后将每一行写入其中。
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")https://stackoverflow.com/questions/66422071
复制相似问题