我已經自動將數字陣列中的數字一一發送到文本框,如下所示,而數字是從陣列中獲取的,同時如何從電子郵件陣列中隨機一一獲取郵件ID?
import time
numbers = [2589001,2589002,2589003,2589004,2589005,2589006,2589007,2589008,2589009,2589010]
email = ["[email protected]","[email protected]","[email protected]","[email protected]","[email protected]"]
def oo() :
for idx in email :
email_from_list = email[idx%len(email)]
#I want to put those email function code here and need to pass this def oo()
c = 0
def vs () :
for idx, nm in enumerate(numbers) :
#Number Input
WebDriverWait(browser, 2500).until(EC.presence_of_element_located((By.NAME, "Number"))).send_keys(nw)
time.sleep(1)
WebDriverWait(browser, 2500).until(EC.presence_of_element_located((By.NAME, "Number"))).send_keys(oo()) #<---- here need to call
time.sleep(1)
#I need code here to get email id one by one randomly from array <--- Fix you wording. You don't actually want them one by one randomly
w = 0
while w < 50 :
vs ()
w = 1
uj5u.com熱心網友回復:
如果您想從串列中隨機獲得一個專案并且不關心以后是否得到相同的專案,請使用random.choice(list)
如果您只希望以隨機順序排列的串列中的所有專案一次,請使用random.shuffle(list)
例子:
import random
numbers = [2589001,2589002,2589003,2589004,2589005,2589006,2589007,2589008,2589009,2589010]
emails = ["[email protected]","[email protected]","[email protected]","[email protected]","[email protected]"]
def vs(number, email):
# each number only once from list
WebDriverWait(browser, 2500).until(EC.presence_of_element_located((By.NAME, "Number"))).send_keys(number)
time.sleep(1)
# random email from list
WebDriverWait(browser, 2500).until(EC.presence_of_element_located((By.NAME, "Email"))).send_keys(email)
time.sleep(1)
for number in random.shuffle(numbers):
vs(number, random.choice(emails))
如果 number 和 email 是一對,請使用 for number, email in random.shuffle(zip(numbers, emails)):
如果您想要隨機的一對數字和串列中只出現一次的電子郵件,請使用 for number, email in zip(random.shuffle(numbers), random.shuffle(emails)):
uj5u.com熱心網友回復:
我已經閱讀了您的評論,您所描述的內容并不是您在原始帖子/問題中所要求的。您想要的是遍歷相同的電子郵件串列(不想選擇隨機電子郵件)。
import time
numbers = [2589001,2589002,2589003,2589004,2589005,2589006,2589007,2589008,2589009,2589010]
email = ["[email protected]","[email protected]","[email protected]","[email protected]","[email protected]"]
c = 0
def vs () :
for idx, nm in enumerate(numbers) :
#Number Input
WebDriverWait(browser, 2500).until(EC.presence_of_element_located((By.NAME, "Number"))).send_keys(nw)
time.sleep(1)
#I need code here to get email id one by one randomly from array <--- Fix you wording. You don't actually want them one by one randomly
email_from_list = email[idx%len(email)]
w = 0
while w < 50 :
vs ()
w = 1
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/330725.html
標籤:Python 蟒蛇-3.x 硒网络驱动程序 蟒蛇请求 硒铬驱动器
上一篇:如何讓Python等待網站彈出?
