Paulo Silveira Xpto
New Member
- Joined
- Aug 27, 2020
- Messages
- 11
- Office Version
- 2016
- Platform
- Windows
Hello, sorry for my bad english. I'm from Brazil. I've bought the book "Excel 2016 VBA & MACROS" by Bill Jelen and Tracy Syrstad.
Here in Brazil by Ed ALTA BOOKS.
I need help to finish a Web Scraping code.
A basic file in Excel, with the first header row with 4 columns:
Número Antigo - Novo - Vara - Data de Autuação
Starting with row 2 and 1st column, there are a series of numbers to be searched on a specific page, namely.
The idea of the code is to launch the Old Number on the page and bring the New + the other 3 datas from there;
Here is a small sequence of numbers to be mined:
200334000111326
200334000111179
200334000107120
200334000107117
200334000105010
When calling the page in question, the code must:
- Click on the "Número de Processo" button, just below "Opções de pesquisa";
- Take the 1st in the spreadsheet and play it in the COMBO "Número do Processo", under CONSULTA PROCESSUAL;
- Click on the "Pesquisar" button;
- As soon as pg loads, bring from there the value of the field "Nova Numeração" + "Vara" + "Data de Autuação";
I still couldn't click on the 1st button, because before, when there was no loop, the code even brought the data, wrong, but it did.
Hence when the loop is triggered, errors arise.
Here is the code:
Sub TRF1_Click()
Dim IE As InternetExplorer
Set IE = New InternetExplorer
IE.Visible = True
Dim col As Integer
Dim ln As Integer
Dim antigo As String
Dim numprocesso As Variant
Dim novoproc As Variant
Dim vara As Variant
Dim datautua As Variant
Dim botao As Variant
Dim UltCel As Range
IE.Navigate "https://processual.trf1.jus.br/consultaProcessual/numeroProcesso.php?secao=DF"
While IE.Busy Or IE.ReadyState <> READYSTATE_COMPLETE
DoEvents
Wend
ln = 2
col = 1
While Cells(ln, col).Value <> ""
antigo = Cells(ln, col).Value
Set numprocesso = IE.Document.all("Número do Processo")
While IE.Busy Or IE.ReadyState <> READYSTATE_COMPLETE
DoEvents
Wend
numprocesso.Click
IE.Document.all("proc").innerText = antigo
While IE.Busy Or IE.ReadyState <> READYSTATE_COMPLETE
DoEvents
Wend
Set botao = IE.Document.getElementById("enviar")
While IE.Busy Or IE.ReadyState <> READYSTATE_COMPLETE
DoEvents
Wend
botao.Click
While IE.Busy Or IE.ReadyState <> READYSTATE_COMPLETE
DoEvents
Wend
Set novoproc = IE.Document.all.tags("td")(1)
Set vara = IE.Document.all.tags("td")(3)
Set datautua = IE.Document.all.tags("td")(5)
Cells(ln, col + 1) = novoproc.innerText
Cells(ln, col + 2) = vara.innerText
Cells(ln, col + 3) = datautua.innerText
ln = ln + 1
novoproc = vbNullString
vara = vbNullString
datautua = vbNullString
antigo = vbNullString
IE.Quit
DoEvents
Wend
End Sub
Here in Brazil by Ed ALTA BOOKS.
I need help to finish a Web Scraping code.
A basic file in Excel, with the first header row with 4 columns:
Número Antigo - Novo - Vara - Data de Autuação
Starting with row 2 and 1st column, there are a series of numbers to be searched on a specific page, namely.
The idea of the code is to launch the Old Number on the page and bring the New + the other 3 datas from there;
Here is a small sequence of numbers to be mined:
200334000111326
200334000111179
200334000107120
200334000107117
200334000105010
When calling the page in question, the code must:
- Click on the "Número de Processo" button, just below "Opções de pesquisa";
- Take the 1st in the spreadsheet and play it in the COMBO "Número do Processo", under CONSULTA PROCESSUAL;
- Click on the "Pesquisar" button;
- As soon as pg loads, bring from there the value of the field "Nova Numeração" + "Vara" + "Data de Autuação";
I still couldn't click on the 1st button, because before, when there was no loop, the code even brought the data, wrong, but it did.
Hence when the loop is triggered, errors arise.
Here is the code:
Sub TRF1_Click()
Dim IE As InternetExplorer
Set IE = New InternetExplorer
IE.Visible = True
Dim col As Integer
Dim ln As Integer
Dim antigo As String
Dim numprocesso As Variant
Dim novoproc As Variant
Dim vara As Variant
Dim datautua As Variant
Dim botao As Variant
Dim UltCel As Range
IE.Navigate "https://processual.trf1.jus.br/consultaProcessual/numeroProcesso.php?secao=DF"
While IE.Busy Or IE.ReadyState <> READYSTATE_COMPLETE
DoEvents
Wend
ln = 2
col = 1
While Cells(ln, col).Value <> ""
antigo = Cells(ln, col).Value
Set numprocesso = IE.Document.all("Número do Processo")
While IE.Busy Or IE.ReadyState <> READYSTATE_COMPLETE
DoEvents
Wend
numprocesso.Click
IE.Document.all("proc").innerText = antigo
While IE.Busy Or IE.ReadyState <> READYSTATE_COMPLETE
DoEvents
Wend
Set botao = IE.Document.getElementById("enviar")
While IE.Busy Or IE.ReadyState <> READYSTATE_COMPLETE
DoEvents
Wend
botao.Click
While IE.Busy Or IE.ReadyState <> READYSTATE_COMPLETE
DoEvents
Wend
Set novoproc = IE.Document.all.tags("td")(1)
Set vara = IE.Document.all.tags("td")(3)
Set datautua = IE.Document.all.tags("td")(5)
Cells(ln, col + 1) = novoproc.innerText
Cells(ln, col + 2) = vara.innerText
Cells(ln, col + 3) = datautua.innerText
ln = ln + 1
novoproc = vbNullString
vara = vbNullString
datautua = vbNullString
antigo = vbNullString
IE.Quit
DoEvents
Wend
End Sub