0

我想知道使用下面的代码将列表 / webelement 变量转换为 .txt 的函数我只能在控制台 en.txt 上读取文件,但不能将其保存在我的电脑上。

recuperation_nom = driver.find_elements_by_class_name("title-3")

for resultat_nom in recuperation_nom:
    print(resultat_nom.text)
4

1 回答 1

1

只需.txt以访问模式打开文件'a',然后将每一行写入其中。

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")
于 2021-03-01T12:42:15.190 回答