使用MSXML2.XMLHTTP登录网站

时间:2014-06-23 15:50:32

标签: excel-vba web-scraping msxml vba excel

我可以使用以下代码登录网站

Sub OpenWmtVO()
On Error GoTo RunWebObjError

Dim ErrorCounter As Integer

SetUpObject

Restart:

'Disable pop-up messages
objIExplorer.Silent = True   
objIExplorer.Visible = True 'for testing change to true    
'open page
objIExplorer.Navigate "https://wmtscheduler.faa.gov/WMT_Login/"

'wait till page is fully opened
Do While objIExplorer.Busy Or Not objIExplorer.ReadyState = 4: DoEvents: Loop

 'set user ID and password in textboxes
objIExplorer.Document.getElementById("hprLogin_chkViewOnly").Click
objIExplorer.Document.getElementById("hprLogin_adUserName").Value = CurUsr
objIExplorer.Document.getElementById("hprLogin_adPass").Value = CurPw

objIExplorer.Document.all.Item("hprLogin$btnSubmit").Click
    Do While objIExplorer.Busy Or Not objIExplorer.ReadyState = 4: DoEvents: Loop

我想使用MSXML2.XMLHTTP,因为它更快,一旦登录,我可以在29到42页之间激发我需要更快的数据。但是,我不知道如何使用MSXML2.XMLHTTP初始登录此站点。任何想法或帮助都会很棒

由于

1 个答案:

答案 0 :(得分:0)

我还没有找到如何让Windows自动传递凭据,但您可以像xmlhttp.Open一样硬编码(" POST",url,false,"用户名" ,"密码")