欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python+Selenium隨機(jī)生成手機(jī)驗(yàn)證碼并檢查頁面上是否彈出重復(fù)手機(jī)號(hào)碼提示框

 更新時(shí)間:2020年09月21日 10:50:58   作者:圓圓的腦袋有很多問號(hào)  
這篇文章主要介紹了Python+Selenium隨機(jī)生成手機(jī)驗(yàn)證碼并檢查頁面上是否彈出重復(fù)手機(jī)號(hào)碼提示框,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

1、隨機(jī)生成格式正確手機(jī)號(hào)碼

# 隨機(jī)產(chǎn)生格式正確的手機(jī)號(hào)碼
def create_phone(self):
  num_start = ['134', '135', '136', '137', '138', '139', '150', '151', '152', '158', '159', '157', '182', '187', '188', '147', '130', '131', '132', '155', '156', '185', '186', '133', '153', '180', '189']
  start = random.choice(num_start) # 隨機(jī)從列表中選擇一個(gè)元素
  end = ''.join(random.sample(string.digits, 8)) # 隨機(jī)生成8個(gè)0-9的字符
  phone_number = start + end
  return phone_number

2、檢查號(hào)碼是否重復(fù)

這里作檢查的前提是,號(hào)碼重復(fù)了頁面上會(huì)彈出重復(fù)的提示語,也可以和后臺(tái)數(shù)據(jù)庫作比較,不過這樣判斷比較快~提示重復(fù)則重新獲取

# 判斷手機(jī)號(hào)碼可不可用,不可用再生成 直到不會(huì)出現(xiàn)錯(cuò)誤提示,這里的xpath是提示框的
if self.driver.find_element_by_xpath('//*[@id="mobileNumberDiv"]/div[3]/div/div[1]'):
  btn_win = WebDriverWait(self.driver, 4).until(
    lambda d: d.find_element_by_xpath('//*[@id="mobileNumberDiv"]/div[3]/div/div[1]'))
  while btn_win.is_displayed():
    phone_number = self.create_phone()
    self.driver.find_element(By.ID, "mobileNumber").clear()
    self.driver.find_element(By.ID, "mobileNumber").send_keys(self.create_phone())

總結(jié)

到此這篇關(guān)于Python+Selenium隨機(jī)生成手機(jī)驗(yàn)證碼并檢查頁面上是否彈出重復(fù)手機(jī)號(hào)碼提示框的文章就介紹到這了,更多相關(guān)Python+Selenium隨機(jī)生成手機(jī)驗(yàn)證碼內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論