如何用python在Selenium中编写文本文件?
通过首先创建一个txt文件并在其中包含内容,我们可以使用python在Selenium中编写文本文件。
首先,我们需要以写模式打开文件,并以文本文件的位置路径作为参数。有多种读取方法可以执行这些操作。
write()–将字符串写在一个文本文件中。
writelines()–它在一个文本文件中写入多个字符串。
示例
用.NET实现代码write()。
#open the file for write operation
f = open('hello.txt' , 'w')
#writes the new content
f.write('Nhooo')
#close the file
f.close()
# again open the file for read
f = open('hello.txt' , 'r')
#reads the file content and prints in console
print(f.read())
#close the file
f.close()代码实现writelines()
#open the file for write operation
f = open('hello.txt' , 'w')
lines = ["Nhooo", "Selenium"]
#writes the new content
f.writelines(lines)
#close the file
f.close()
# again open the file for read
f = open('hello.txt' , 'r')
#reads the file content and prints in console
print(f.read())
#close the file
f.close()热门推荐
1 如何训练狗狗不叫
2 训练狗狗不叫
3 训练狗狗随行
4 怎么训练狗狗不叫
7 训练比熊狗狗教程
10 上海狗狗训练
11 怎么训练狗狗上厕所
12 训练狗狗趴下
13 狗狗服从训练
14 训练狗狗拒食
15 训练狗狗笑
16 训练狗狗大便
17 训练狗狗立
18 训练狗狗捡东西