导航网站和获取数据时拒绝权限

时间:2016-05-16 18:28:46

标签: excel vba excel-vba

我正在使用excel vba尝试以下内容。

  1. 导航到网站
  2. 从页面获取数据
  3. 导航到页面上的另一个href链接
  4. 从新页面获取数据
  5. 以下代码抛出“运行时错误70:权限被拒绝”错误。我也试过了另一种方式 - 导航到第一页,然后从第一页获取数据 - 导航到第二页并从第二页获取数据

    但那也没有用。

    Sub ImportAssortments()
    
    Dim ie As InternetExplorer
    
    Dim html As HTMLDocument
    Dim i As Integer
    Dim Text As HTMLDocument
    Dim a As Integer
    Dim b As Integer
    Dim c As Integer
    Dim uDD(1 To 2) As IHTMLElementCollection
    Dim el As Object
    
    
    b = 0
    
    Set ie = New InternetExplorer
    ie.Visible = True
    
    ie.navigate "http://www.example.com"
    
    Do While ie.readyState <> READYSTATE_COMPLETE
       Application.StatusBar = "Trying to get Snapdeal Data... Please wait"
       DoEvents
    Loop
    
    Set html = ie.document
    Set uDD(1) = html.getElementsByTagName("li")
    
    ie.navigate html.getElementById("pagnNextLink")
    
    Do While ie.readyState <> READYSTATE_COMPLETE
        Application.StatusBar = "Trying to get the Data... Please wait"
        DoEvents
    Loop
    
    Set html = ie.document
    
    Set uDD(2) = html.getElementsByTagName("li")
    
    For i = 1 To 2
    
        For Each el In uDD(i)
            If InStr(el.innerText, "stars") <> 0 Then
               y = y + 1
               Cells(y, 1) = el.innerText
            End If
            If y = 24 Then Exit For
        Next el
    
    Next i
    
    Set ie = Nothing
    Application.StatusBar = ""
    
    End Sub
    

0 个答案:

没有答案