从文本文件 pwd email 中读取

现在我的代码是


email = 'test@gmail.com'

pwd = 'testing123'

 

user.send_keys(email)

user.send_keys(pwd)

现在我想从文本文件中读取电子邮件和密码,这是代码上的。


假设我在尝试使用 f 打开的同一文件夹中有一个 info.txt 但它不起作用,我完全迷失了


 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)

 


千巷猫影
浏览 95回答 1
1回答

梦里花落0921

我认为你可以使用读取文件open("info.txt","r")然后附加 email 和 pwd 变量。阅读文件后,您可以使用 split 来分隔单词。f = open("info.txt","r")x = f.read().split("\n")f.close()email = x[0]passwd = x[1]print(email,passwd)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python