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"
原文地址:https://www.cnblogs.com/2zhyi/p/3345141.html