3 回答
TA贡献1799条经验 获得超8个赞
使用:
myfile = open("text.txt","r") # text.txt is the file name, r means read file.
contents = myfile.read()
print(contents)
myfile.close()
TA贡献1817条经验 获得超14个赞
这是使用正则表达式的方法:
import re
# There would be other code here to set up Selenium and
# define the variable `driver`
with open('/tmp/data.txt') as f:
buf = f.read()
expr = re.compile(r"email:\s*([^\s]+)\s+password: (.*)")
m = expr.match(buf)
if m:
email = m.group(1)
password = m.group(2)
search = driver.find_element_by_name("emailAddress")
search.send_keys(email)
TA贡献1851条经验 获得超3个赞
尝试这个:
with open("file/location.txt","r") as f:
txt = f.read()
email = txt.split("password")[0].split(":")[1].strip()
password = txt.split(":")[2].strip()
添加回答
举报