Vba web scraping

Asked

Viewed 193 times

1

Hello, I have a problem when performing a web Scrapping on the site "https://esaj.tjsp.jus.br/cpopg/open.do"

In VBA I can open the site and everything and even enter the values I want, the problem is that it has a dropdown "Search for", that when selecting by the browser in the dropdown "Part document", it seems that it enables a script that then enables the input Process number. Thing that by vba, it does not enable, so it inserts the value, but it seems that only as if it were in the placeholder.

So in short, what I want to do is this:

  1. Open this site in VBA ("https://esaj.tjsp.jus.br/cpopg/open.do")

RESEARCH DATA

  1. Forum => "All forums in the list below"
  2. Search by (Dropdown) => "Part document"
  3. Process number => "Any valid cnpj"
  4. Search.Click()
  • Please enter the code you use.

1 answer

1

Good morning Juny hope the code below helps

First step is to configure references.

in the VBA IDE go to Tools > References then check the options: Microsoft Internet Controls and Microsoft HTML Object Library

Sub Bot()
    Dim objIE As Object
    Dim aEle As HTMLLinkElement

    Dim result As String
    Dim CNPJ As String
    Dim URL As String

    Set objIE = New InternetExplorer
    CNPJ = "123456789" 'pode apontar para uma célula
    URL = "https://esaj.tjsp.jus.br/cpopg/open.do" 'pode apontar para uma célula
    objIE.Visible = True

    objIE.navigate URL

    Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop

    objIE.document.all.Item("cbPesquisa").selectedIndex = 2 'posição do item documento da parte
    objIE.document.all.Item("cbPesquisa").FireEvent ("onchange") 'atualiza seleção
    objIE.document.all.Item("campo_DOCPARTE").Value = CNPJ 'CNPJ
    objIE.document.all.Item("pbEnviar").Click 'click

    CNPJ = ""
    URL = ""
    Set objIE = Nothing
End Sub

Browser other questions tagged

You are not signed in. Login or sign up in order to post.