python - 如何从文本文件中获取数据,然后在 Python 文件中使用提取的数据?
问题描述
我有一个包含我的电子邮件和密码地址的文本文件,
文本文件:
电子邮件:email@address.com
密码:password123
我想使用变量“email”从文本文件中提取数据,并使用 Selenium 将其输入到我的代码中。
例如:
search = driver.find_element_by_name("emailAddress")
search.send_keys(EmailFromTextFile)
如何?
解决方案
利用:
myfile = open("text.txt","r") # text.txt is the file name, r means read file.
contents = myfile.read()
print(contents)
myfile.close()
您可以在Python File Open中获得有关 Python 文件处理的更多信息。
推荐阅读
- python - 如何提取numpy数组的非零值
- kubernetes - 发生内部错误:调用 webhook “validate.nginx.ingress.kubernetes.io”失败
- python - 如何在当前命令提示符窗口中运行脚本?
- webassembly - Uno Platform 应用程序中未定义无参数构造函数
- python - 如何将三个 if 语句合并为一个?
- android - 将图像上传到存储 Firebase 不起作用
- wordpress - WordPre - 将 ROLE 属性添加到菜单项
- javascript - 如何从 shapefile 访问属性数据以使用传单使叶绿素反应?
- php - 按属性对 JSON 对象进行分组并在数组中拆分结果 PHP | 拉拉维尔
- sql - SQL Server:根据列上的前几个字符查找重复项