Notifications
Clear all

Macro de busca web ML

7 Posts
2 Usuários
0 Reactions
1,050 Visualizações
(@chavez180)
Posts: 0
New Member
Topic starter
 

Galera, help me!!!

Já pesquisei em 3000000000 sites, videos no youtube e já adquiri 1 bilhão de técnicas para busca de informações na web. Porém meu problema é o seguinte: preciso criar uma planilha que colete algumas informações do mercado livre, como o preço do produto, valor do frete, descrição, efim. Mas não estou conseguindo.

Vou mandar o código que eu desenvolvi até o momento e quem puder me ajudar eu serei muito grato.

Valeeew.

Sub BuscaDados_Operador()
    
    Dim IE As Object
    Dim iLin As Long

    iLin = 4

While Cells(iLin, "C").Text <> ""
If Cells(iLin, "E").Text = "" Then
       'instancia um objeto do Internet Explorer e o torna visivel
       Set IE = CreateObject("internetexplorer.application")
       IE.Visible = False
     
       'vai para a página que você quer capturar
       IE.navigate Cells(iLin, "D").Text
       
       Do While IE.busy
       Loop
    
    Set objCollection = IE.Document.getelementsbytagname("Preço")
       i = 0
           
       While i < objCollection.Length
           If objCollection(i).innerText = "Preço" Then
               ' Set text to enter
               sValor = objCollection(i).ParentNode.innerText
               Cells(iLin, "E").Value = Trim(Replace(Replace(sValor, "Preço", ""), "R$", ""))
               
                
           End If
                
           i = i + 1
       Wend
    CloseIE
End If
   iLin = iLin + 1
    ii = 0
    Do While ii < 10000
        ii = ii + 1
    Loop
Wend
End Sub

Public Sub CloseIE()
    Dim Shell As Object
    Dim IE As Object
 
    Set Shell = CreateObject("Shell.Application")
 
    For Each IE In Shell.Windows
        If TypeName(IE.Document) = "HTMLDocument" Then
            IE.Quit
        End If
    Next
End Sub
 
Postado : 18/10/2016 7:31 am
(@djunqueira)
Posts: 0
New Member
 

Uma das soluções mais avançadas q eu já vi p/ o assunto foi montada pelo nosso colega Mikel na planilha anexa.

 
Postado : 18/10/2016 7:52 am
(@chavez180)
Posts: 0
New Member
Topic starter
 

Djunqueira, obrigado pela resposta, mais o link não abre aqui, poderia reencaminhar o arquivo?

 
Postado : 18/10/2016 8:16 am
(@djunqueira)
Posts: 0
New Member
 

Vamos ver se zipado vai...

 
Postado : 18/10/2016 8:41 am
(@chavez180)
Posts: 0
New Member
Topic starter
 

Não abre, diz que o arquivo de origem não pode ser lido.

 
Postado : 18/10/2016 9:37 am
(@djunqueira)
Posts: 0
New Member
 

Tente este link do OneDrive:
https://1drv.ms/x/s!AhXzOGVf0n4bmSTZS4KpACB8uZbC

 
Postado : 18/10/2016 10:23 am
(@chavez180)
Posts: 0
New Member
Topic starter
 

DJunqueira, muito obrigado pelas informações, consegui abrir e vai me ajudar muito nos estudos.

Consegui criar uma planilha com um botton de pesquisa que me trás o valor que preciso, caso alguém precise do código futuramente segue abaixo:

'Cod planilha

S

ub BuscaDados_Operador()
    
    Dim IE As Object
    Dim iLin As Long

    iLin = 4

While Cells(iLin, "C").Text <> ""
If Cells(iLin, "E").Text = "" Then
       'instancia um objeto do Internet Explorer e o torna visivel
       Set IE = CreateObject("internetexplorer.application")
       IE.Visible = False
     
       'vai para a página que você quer capturar
       IE.navigate Cells(iLin, "D").Text
       
       Do While IE.busy
       Loop
    
    Set objCollection = IE.Document.getelementsbytagname("legend")
       i = 0
           
       While i < objCollection.Length
           If objCollection(i).innerText = "Preço" Then
               ' Set text to enter
               sValor = objCollection(i).ParentNode.innerText
               Cells(iLin, "E").Value = Trim(Replace(Replace(sValor, "Preço", ""), "R$", ""))
                
                
           End If
           i = i + 1
       Wend
    CloseIE
End If
   iLin = iLin + 1
    ii = 0
    Do While ii < 10000
        ii = ii + 1
    Loop
Wend
End Sub

Public Sub CloseIE()
    Dim Shell As Object
    Dim IE As Object
 
    Set Shell = CreateObject("Shell.Application")
 
    For Each IE In Shell.Windows
        If TypeName(IE.Document) = "HTMLDocument" Then
            IE.Quit
        End If
    Next
End Sub


'Cod CMBotton


Private Sub cmdb_Click()
    
    
If (ActiveCell.Row > 4 And Cells(ActiveCell.Row, "D").Text <> "") Or txtb.Text <> "" Then
    
    txtb.Value = Cells(ActiveCell.Row, "D").Text

    If txtb.Text <> "" Then
        Dim IE As Object
           'instancia um objeto do Internet Explorer e o torna visivel
           Set IE = CreateObject("internetexplorer.application")
           IE.Visible = False
         
           'vai para a página que você quer capturar
           IE.navigate txtb.Text
           
           Do While IE.busy
           Loop
        
        Set objCollection = IE.Document.getelementsbytagname("legend")
           i = 0
               
           While i < objCollection.Length
               If objCollection(i).innerText = "Preço" Then
                   ' Set text to enter
                   sValor = objCollection(i).ParentNode.innerText
                   Cells(ActiveCell.Row, "E").Value = Trim(Replace(Replace(sValor, "Preço", ""), "R$", ""))
                    
                    
               End If
               i = i + 1
           Wend
        CloseIE
    End If
       iLin = iLin + 1
        ii = 0
        Do While ii < 10000
            ii = ii + 1
        Loop
        Set IE = Nothing
        txtb.Value = ""
End If

End Sub
 
Postado : 18/10/2016 11:26 am