使用VBA从网站提取数据会一遍又一遍地返回相同的值

时间:2018-03-29 17:58:06

标签: excel-vba vba excel

所以我有这个问题。 此代码应从电子表格中获取URL,打开它并提取特定数据。 比它应该下去一行,抓住另一个URL并做同样的事情。 但它只返回第一次搜索的值... 我究竟做错了什么?这是4个网址

  1. https://www.sitemercado.com.br/laranjao/jose-bonifacio-loja-sao-jose-sao-jose-avenida-joaquim-moreira-silva/arroz-tipo-1-prato-fino-embalagem-1kg
  2. https://www.sitemercado.com.br/laranjao/jose-bonifacio-loja-sao-jose-sao-jose-avenida-joaquim-moreira-silva/arroz-tipo-1-prato-fino-pacote-5kg
  3. https://www.sitemercado.com.br/laranjao/jose-bonifacio-loja-sao-jose-sao-jose-avenida-joaquim-moreira-silva/arroz-tipo-1-rosalito-pacote-5kg
  4. https://www.sitemercado.com.br/laranjao/jose-bonifacio-loja-sao-jose-sao-jose-avenida-joaquim-moreira-silva/arroz-tipo-1-rosalito-extra-premium-pacote-1kg
  5. Printscreen from spreadsheet

       Sub a()
    
    Set objIE = CreateObject("InternetExplorer.Application")
    objIE.Top = 0
    objIE.Left = 0
    objIE.Width = 800
    objIE.Height = 600
    objIE.Visible = False 'We will see the window navigation
    
    On Error Resume Next
    
    Dim i As Long
    For i = 15 To 19
    
    linkprod = Range("A" & i)
    
    objIE.navigate (linkprod)
    
    Do
    DoEvents
    
        If Err.Number <> 0 Then
            objIE.Quit
            Set objIE = Nothing
    
        End If
    Loop Until objIE.readystate = 4
    
    txtHtml.Text = objIE.document.body.innerhtml
    objIE.document.getElementsByClassName("kg")(0).innerText
     Text = objIE.document.getElementsByClassName("kg")(0).innerText
        Range("k" & i) = Text
    
    
    Next i
    
    End Sub
    

0 个答案:

没有答案