这是使用正则表达式的方法: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)