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,
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,214,784
Messages
6,121,535
Members
449,037
Latest member
tmmotairi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top