使用VBA从密码保护网站数据(Data from password protected websit

2019-09-17 02:42发布

使用Excel 2007和VBA 6.5

我试图自动化数据收集任务,但我一直运行到“运行时错误91 - ‘对象变量或带块变量未设置’这是一个参考的问题或者它与我的脚本来执行。

谢谢。

脚本包含以下(密码和可变保护)

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

Answer 1:

更改这些行

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

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

然后再试一次。



文章来源: Data from password protected website using VBA