我是靠谱客的博主 羞涩宝马,这篇文章主要介绍Selenium虚拟邮箱验证码获取,现在分享给大家,希望可以做个参考。

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from time import sleep
import re

def getcode(chrome):
    js = 'window.open("https://www.snapmail.cc/zh#/emailList/lulu@snapmail.cc");'
    sleep(2)
    chrome.execute_script(js)
    # 输出当前窗口句柄(flycoin)
    dc_handle = chrome.current_window_handle
    # 获取当前窗口句柄集合(列表类型)
    handles = chrome.window_handles
    print(handles)  # 输出句柄集合
    mail_handle = None
    for handle in handles:
        if handle != dc_handle:
            mail_handle = handle
    chrome.switch_to.window(mail_handle)
    print(chrome.title)

    # chrome.get('https://www.snapmail.cc/zh#/emailList/lulu@snapmail.cc')

    chrome.find_element_by_xpath('//span[@style="margin-left: 20px;margin-right: 5px"]').click()
    sleep(1)
    chrome.switch_to.frame(chrome.find_element_by_xpath('//iframe[@class="preview-iframe panel-html"]'))
    code=chrome.find_element_by_xpath('//h1[@style="text-align: center;"]').get_attribute('innerText')
    chrome.close()
    chrome.switch_to.window(dc_handle)
    return code

        选取的元素是最新的一条未读消息,frame内的xpath需要更改

        Selenium是模拟操作,所以我用句柄的方式新开窗口,取到验证码之后再返回原窗口

最后

以上就是羞涩宝马最近收集整理的关于Selenium虚拟邮箱验证码获取的全部内容,更多相关Selenium虚拟邮箱验证码获取内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(50)

评论列表共有 0 条评论

立即
投稿
返回
顶部