python - 如何从python中的文本文件中复制所有文本(使用ctrl + c和ctrl + a命令)?
问题描述
我正在写一个硒项目。
我试图创建一个函数,使用 ctrl + A、ctrl + C 复制文本文件中的所有文本。
def Copy(driver) :
f = open("out1.txt") # open the text file
.click() #i need to click on the file
.send_keys(Keys.CONTROL, 'a') # select all the text
time.sleep(1)
.send_keys(Keys.CONTROL, 'c') # copy the text in my clipboard
f.close()
这就是我尝试编写的代码,但我没有管理。有什么帮助吗?
解决方案
您应该使用 Python 的内置文件读/写函数。 https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files
对于您的示例,您可以这样做。
with open('out1.txt', 'r') as f:
data = f.readlines()
推荐阅读
- spring-webflux - webflux单声道
onErrorReturn 未调用 - java - 从页面上的帖子中获取所有照片
- npgsql - 使用 EF Core 为 npgsql 创建架构失败
- java - 使用 JCo SAP 运行 SAP BAPI 时,getNumRows() 返回 0
- angular - Ionic 4 自定义图标无法在 Android 或 IOS 模拟器和设备上正确显示
- php - 如果查询未找到任何匹配项
- php - 防止在文本字段中检查元素
- php - 需要在预览中的每个图像上都有水印,即使在 Laravel PHP 脚本中下载后也是如此
- php - Paypal - 自动计算运费不起作用
- http - 如何重试 HTTP POST 请求