Login website and parsing json

Valter Paulista

New Member
Joined
Jun 21, 2018
Messages
1
Hi,

I've a code to import a Json text to excel.

There is a way to do a web request to login to the site (probably get cookies too) and parse directly the json url?

Code:
[COLOR=#2E8B57][FONT=Monaco]Sub ConverterJsonEfatura()[/FONT][/COLOR]
[COLOR=#2E8B57][FONT=Monaco]Dim jsonText As String[/FONT][/COLOR]
[COLOR=#2E8B57][FONT=Monaco]Dim jsonObject As Object, item As Object[/FONT][/COLOR]
[COLOR=#2E8B57][FONT=Monaco]Dim i As Long[/FONT][/COLOR]
[COLOR=#2E8B57][FONT=Monaco]Dim ws As Worksheet[/FONT][/COLOR]

[COLOR=#2E8B57][FONT=Monaco]Set ws = Worksheets("Folha1")[/FONT][/COLOR]

[COLOR=#2E8B57][FONT=Monaco]jsonText = ws.Cells(1, 1)[/FONT][/COLOR]

[COLOR=#2E8B57][FONT=Monaco]Set jsonObject = JsonConverter.ParseJson(jsonText)[/FONT][/COLOR]

[COLOR=#2E8B57][FONT=Monaco]i = 3[/FONT][/COLOR]

[COLOR=#2E8B57][FONT=Monaco]For Each item In jsonObject("linhas")[/FONT][/COLOR]
[COLOR=#2E8B57][FONT=Monaco]    ws.Cells(i, 1) = item("idDocumento")[/FONT][/COLOR]
[COLOR=#2E8B57][FONT=Monaco]    ws.Cells(i, 2) = item("origemRegisto")[/FONT][/COLOR]
[COLOR=#2E8B57][FONT=Monaco]    ws.Cells(i, 3) = item("origemRegistoDesc")[/FONT][/COLOR]
[COLOR=#2E8B57][FONT=Monaco]    ws.Cells(i, 4) = item("nifEmitente")[/FONT][/COLOR]
[COLOR=#2E8B57][FONT=Monaco]    ws.Cells(i, 5) = item("nomeEmitente")[/FONT][/COLOR]
[COLOR=#2E8B57][FONT=Monaco]    ws.Cells(i, 6) = item("nifAdquirente")[/FONT][/COLOR]
[COLOR=#2E8B57][FONT=Monaco]    ws.Cells(i, 7) = item("nomeAdquirente")[/FONT][/COLOR]
[COLOR=#2E8B57][FONT=Monaco]    ws.Cells(i, 8) = item("tipoDocumento")[/FONT][/COLOR]
[COLOR=#2E8B57][FONT=Monaco]    ws.Cells(i, 9) = item("tipoDocumentoDesc")[/FONT][/COLOR]
[COLOR=#2E8B57][FONT=Monaco]    ws.Cells(i, 10) = item("numerodocumento")[/FONT][/COLOR]
[COLOR=#2E8B57][FONT=Monaco]    ws.Cells(i, 11) = item("dataEmissaoDocumento")[/FONT][/COLOR]
[COLOR=#2E8B57][FONT=Monaco]    ws.Cells(i, 12) = item("valorTotal") / 100[/FONT][/COLOR]
[COLOR=#2E8B57][FONT=Monaco]    ws.Cells(i, 13) = item("valorTotalBaseTributavel") / 100[/FONT][/COLOR]
[COLOR=#2E8B57][FONT=Monaco]    ws.Cells(i, 14) = item("valorTotalIva") / 100[/FONT][/COLOR]
[COLOR=#2E8B57][FONT=Monaco]  [/FONT][/COLOR]
[COLOR=#2E8B57][FONT=Monaco]    i = i + 1[/FONT][/COLOR]
[COLOR=#2E8B57][FONT=Monaco]Next[/FONT][/COLOR]

[COLOR=#2E8B57][FONT=Monaco]End Sub[/FONT][/COLOR]
Thanks in advance.

https://faturas.portaldasfinancas.g...Filter=2018-05-18&ambitoAquisicaoFilter=TODOS

Regards,
 

Some videos you may like

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Watch MrExcel Video

Forum statistics

Threads
1,102,326
Messages
5,486,172
Members
407,536
Latest member
farrukhikram

This Week's Hot Topics

Top