现在我的代码是
email = 'test@gmail.com'
pwd = 'testing123'
user.send_keys(email)
user.send_keys(pwd)
现在我想从文本文件中读取电子邮件和pwd,这是代码。
假设我在同一个文件夹中有一个info.txt我试着打开f,但它不起作用,我完全失去了
email = 'test@gmail.com'
pwd = 'testing123'
msg = 'testy123'
driver = webdriver.Chrome('chromedriver.exe', options=options)
driver.get('https://www.randomsite.com')
print ("Logging in and doing requests.")
user = driver.find_element_by_id('login_email')
user.send_keys(email)
password = driver.find_element_by_id('login_password')
password.send_keys(pwd)
我认为您可以使用open("info.txt","r")
读取文件
然后添加电子邮件和pwd变量。你可以在阅读文件后使用split,这样你就可以把单词分开。
f = open("info.txt","r")
x = f.read().split("n")
f.close()
email = x[0]
passwd = x[1]
print(email,passwd)