3 回答

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超8個(gè)贊
使用:
myfile = open("text.txt","r")? # text.txt is the file name, r means read file.
contents = myfile.read()
print(contents)
myfile.close()

TA貢獻(xiàn)1817條經(jīng)驗(yàn) 獲得超14個(gè)贊
這是使用正則表達(dá)式的方法:
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貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超3個(gè)贊
嘗試這個(gè):
with open("file/location.txt","r") as f:
txt = f.read()
email = txt.split("password")[0].split(":")[1].strip()
password = txt.split(":")[2].strip()
添加回答
舉報(bào)