硒创建批量电子邮件地址

时间:2019-03-08 15:47:54

标签: selenium email

我想使用硒一次创建多个电子邮件地址。我想它们可以是随机的,但我已经有了要创建的电子邮件帐户名称的列表。

我知道如何使用webdriver创建1封电子邮件,但是如果我要自动签署几封电子邮件,而又不必总是更改代码,该如何处理呢?

用于创建1封电子邮件的简单代码:

from selenium import webdriver
import time

url = 'https://hotmail.com/'

driver = webdriver.Chrome('/C:Users/Desktop/chromedriver')
driver.get(url)

driver.find_element_by_xpath("//a[contains(@class, 'linkButtonSigninHeader')]/@href").click()
time.sleep(2)

driver.find_element_by_id('MemberName').send_keys('usernameexample')
time.sleep(1)

driver.find_element_by_id('iSignupAction).click()
time.sleet(2)

driver.find_element_by_id('PasswordInput').send_keys('Passwordexample1')
time.sleep(1)

driver.find_element_by_id('iSignupAction').click()
time.sleep(2)

driver.find_element_by_id('FirstName').send_keys('john')
time.sleep(1)

driver.find_element_by_id('LastName').send_keys('wayne')
time.sleep(1)

driver.find_element_by_id('iSignupAction').click()

1 个答案:

答案 0 :(得分:0)

正如其他人指出的那样,您可以遍历数据收集,例如数组:

array_of_usernames = ['username_one', 'username_two']

array_of_usernames.each do |username|

  url = 'https://hotmail.com/'

  driver = webdriver.Chrome('/C:Users/Desktop/chromedriver')
  driver.get(url)

  driver.find_element_by_xpath("//a[contains(@class, 'linkButtonSigninHeader')]/@href").click()
  driver.find_element_by_id('MemberName').send_keys("#{username}")  #INTERPOLATED BLOCK-LOCAL VARIABLE HERE
  driver.find_element_by_id('iSignupAction).click()
  driver.find_element_by_id('PasswordInput').send_keys('Passwordexample1')
  driver.find_element_by_id('iSignupAction').click()
  driver.find_element_by_id('FirstName').send_keys('john')
  driver.find_element_by_id('LastName').send_keys('wayne')
  driver.find_element_by_id('iSignupAction').click()

  # some step to log out so that next username can register

end

如果您不熟悉数组或迭代,那么我建议您看一下文档以了解它:https://ruby-doc.org/core-2.6.1/Array.html#method-i-each