現在我的代碼是email = '[email protected]'pwd = 'testing123' user.send_keys(email)user.send_keys(pwd)現在我想從文本文件中讀取電子郵件和密碼,這是代碼上的。假設我在嘗試使用 f 打開的同一文件夾中有一個 info.txt 但它不起作用,我完全迷失了 email = '[email protected]'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)
1 回答

夢里花落0921
TA貢獻1772條經驗 獲得超6個贊
我認為你可以使用讀取文件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)
添加回答
舉報
0/150
提交
取消