zoukankan      html  css  js  c++  java
  • powershell 自动 登陆邮箱

    登陆 Gmail:

    function
    WaitForLoad ($ie) { while ($ie.Busy) { sleep -milliseconds 50 } } ############################################## $ie = New-Object -COM InternetExplorer.Application $ie.Navigate("https://mail.google.com/mail/u/0/#inbox") $ie.Visible = $true WaitForLoad($ie) $email = $ie.Document.getElementByID("Email") $pwd=$ie.Document.getElementByID("Passwd") $btnLogin =$ie.Document.getElementByID("signIn") $email.value="your email address@gmail.com" #需要修改 $pwd.value="passwd" #需要修改
     $btnLogin.click(); 
    ############ write email
    print "exit"
    登陆QQ邮箱:

    function
    WaitForLoad ($ie) { while ($ie.Busy) { sleep -milliseconds 50 } } ############################################## $ie = New-Object -COM InternetExplorer.Application $ie.Navigate("https://mail.qq.com/cgi-bin/loginpage") $ie.Visible = $true WaitForLoad($ie) $email = $ie.Document.getElementByID("uin") $pwd=$ie.Document.getElementByID("p") $btnLogin =$ie.Document.getElementByID("btlogin") # Logo $email.value="your QQ " #需要修改 $pwd.value="passwd" #修改要修改 $btnLogin.click(); # write email $innertext="邮箱首页" $link = $ie.Document.getElementsByTagName("A") | where-object {$_.innerText -eq $innertext} $link.outerHTML
    function:

    Function
    NavigateTo([string] $url, [int] $delayTime = 100) { Write-Verbose "Navigating to $url" $global:ie.Navigate($url) WaitForPage $delayTime } Function WaitForPage([int] $delayTime = 100) { $loaded = $false while ($loaded -eq $false) { [System.Threading.Thread]::Sleep($delayTime) #If the browser is not busy, the page is loaded if (-not $global:ie.Busy) { $loaded = $true } } $global:doc = $global:ie.Document } Function SetElementValueByName($name, $value, [int] $position = 0) { if ($global:doc -eq $null) { Write-Error "Document is null" break } $elements = @($global:doc.getElementsByName($name)) if ($elements.Count -ne 0) { $elements[$position].Value = $value } else { Write-Warning "Couldn't find any element with name ""$name""" } } Function ClickElementByName($name, [int] $position = 0) { if ($global:doc -eq $null) { Write-Error "Document is null" break } $elements = @($global:doc.getElementsByName($name)) if ($elements.Count -ne 0) { $elements[$position].Click() WaitForPage } else { Write-Error "Couldn't find element with name ""$name"" at position ""$position""" break } } Function ClickLinkByInnerText($innertext,[int] $delayTime = 0) { if ($script:doc -eq $null) { Write-Error “Document is null” break } sleep -Seconds $delayTime $link = $script:doc.getElementsByTagName(‘A’) | where-object {$_.innerText -eq $innertext} if ($link -ne $null) { $link.Click() WaitForPage } else { Write-Error “Couldn’t find link with innertext “”$innertext"” break } } #Run the script $verbosePreference = "Continue" $global:ie = New-Object -com "InternetExplorer.Application" $global:ie.Navigate("about:blank") $global:ie.visible = $True NavigateTo "https://mail.qq.com/cgi-bin/loginpage" SetElementValueByName "uin" "userName" SetElementValueByName "p" "pwd" ClickElementByName "btlogin" ClickLinkByInnerText "composebtn"
  • 相关阅读:
    java中的数组
    java中的break continue
    java 自加和短路问题 几个例子
    循环语句
    K-近邻算法小结
    数据结构与算法学习笔记 (三) 排序 搜索
    数据结构与算法学习笔记 (二) 栈 链表 队列 树 堆 图 并查集
    Spark数据分析技术学习笔记(一)——基础概念、RDD使用
    Python数据分析学习笔记
    Python机器学习(Sebastian著 ) 学习笔记——第六章模型评估与参数调优实战(Windows Spyder Python 3.6)
  • 原文地址:https://www.cnblogs.com/2zhyi/p/3345141.html
Copyright © 2011-2022 走看看