VBA和Excel:绕过Siteminder保护的身份验证浏览站点
我的目标是:自动进入intranet站点以获取.xls文件中的数据 初步解释:我通过手动操作在一天内定期获取大量数据;我需要一个自动解决方案来节省时间。 可用手段:Excel和Vba(我的公司建立的外部约束) 我所做的第一次尝试是执行登录操作(受Siteminder保护)并加入主页:VBA和Excel:绕过Siteminder保护的身份验证浏览站点,excel,vba,authentication,web,siteminder,Excel,Vba,Authentication,Web,Siteminder,我的目标是:自动进入intranet站点以获取.xls文件中的数据 初步解释:我通过手动操作在一天内定期获取大量数据;我需要一个自动解决方案来节省时间。 可用手段:Excel和Vba(我的公司建立的外部约束) 我所做的第一次尝试是执行登录操作(受Siteminder保护)并加入主页: Sub enter_site() Dim myId As String, myCode As String Dim s3 As Worksheet Dim IE As Object, frm As Object S
Sub enter_site()
Dim myId As String, myCode As String
Dim s3 As Worksheet
Dim IE As Object, frm As Object
Set s3 = ThisWorkbook.Worksheets("Sheet3")
myId = s3.Range("I1")
myCode = s3.Range("K1")
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
.navigate "https://intranetsite.com/up-password/LoginUp-Password.jsp?TARGET2=https://intranetsite.com/up-password/login/login_redirect.html"
While .Busy Or .readyState <> 4: DoEvents: Wend
'LOGIN
Set frm = .document.forms(1)
frm.Item("USER").Value = myId
frm.Item("PASSWORD").Value = myCode
Application.Wait (Now + TimeValue("0:00:02"))
frm.submit
While .Busy Or .readyState <> 4: DoEvents: Wend
End With
‘CHANNEL TOWARDS HOME PAGE
With IE
.navigate "https://site2.intranet.com/mask/home.aspx"
While .Busy Or .readyState <> 4: DoEvents: Wend
End With
然后,我利用本页中的提示捕获了两个相关cookie:
我把它们放在两个牢房里:
Dim ck1 As String
Dim ck2 As String
ck1 = Sheets(2).Range("B12")
ck2 = Sheets(2).Range("B13")
假设以下值:
ck1=“JSESSIONID=blabla”
ck2=“BIGipServerauth-=zzzzzzzzzzzzzz”
此外,如上所述,我有:
myId = s3.Range("I1") '<<< Username (johnsmith)
myCode = s3.Range("K1") '<<< Password (london55)
我应该如何构建post请求?(我注意到我可能需要捕获其他cookie:_WL_AUTHCOOKIE_JSESSIONID和SMSESSION)。
(我不知道SMENC到底是什么;无论如何,我可以使用USER和PASSWORD中存储的变量轻松构建它)
myId = s3.Range("I1") '<<< Username (johnsmith)
myCode = s3.Range("K1") '<<< Password (london55)
POST https://intranetsite.com/siteminderagent/forms/login.fcc HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Referer: https://intranetsite.com/up-password/LoginUp-Password.jsp?TARGET2=https://intranetsite.com/up-password/login/login_redirect.html _redirect.html
Accept-Language: it-IT
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
Host: intranetsite.com
Content-Length: 181
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: JSESSIONID=…..; BIGipServerauth-……..; _WL_AUTHCOOKIE_JSESSIONID=…; SMSESSION=…
SMENC=UTF-8&target……..login_redirect.html&smauthreason=0&USER=johnsmith&PASSWORD=london55