Data from password protected website using VBA

坚强是说给别人听的谎言 提交于 2019-12-07 12:14:46

问题


using Excel 2007 and VBA 6.5

I'm trying to automate a data collection task, however i keep running into the "Runtime Error 91 - "Object Variable or With Block Variable not Set." Is this a reference issue or does it have to do with my script.

Thanks.

Script is included below (password and variable protected)

Sub Basic_Web_Query()

Set ie = CreateObject("InternetExplorer.Application")
    With ie
        .Visible = True
        .Navigate "https://www.urbics.com/Login.php"
        Do Until .ReadyState = 4
            DoEvents
        Loop
        .document.all.Item("User Name").Value = "UserName"
        .document.all.Item("Password").Value = "Password"
        .document.forms(0).submit
    End With

With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.urbics.com/Urbics.php?hs=a97cd706q9948q11e1qbbacq00259002436c&pgreq=AVTotals&aid=4517", Destination:=Range("$B$4"))

.Name = "q?s=goog_2"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "1,2"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False

End With
End Sub

回答1:


Change these lines

    .document.all.Item("User Name").Value = "UserName"
    .document.all.Item("Password").Value = "Password"

to

    .document.all.Item("loginUserName").Value = "UserName"
    .document.all.Item("loginUserPassword").Value = "Password"

And try again.



来源:https://stackoverflow.com/questions/10506833/data-from-password-protected-website-using-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!