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()
添加回答
舉報