Power Bi - Get Data From Post Request
I'm trying to get the .cvs file from https://www2.cetip.com.br/TitulosCRI into power BI automatically. In order to do download the file manually, you must first click in the button
Solution 1:
Lucca, I believe you're from Brasil, but anyway I'll write in english so people can understand the answer, ok?
I'm trying for some years to scrape this webpage (with R, python and excel+vba), and finally I found a solution: here and here.
I found a solution within Excel + VBA. That I post bellow:
OptionExplicitPublicDeclareSub Sleep Lib"kernel32" (ByVal dwMilliseconds AsLong)
PrivateDeclareFunction FindWindowEx Lib"user32"Alias"FindWindowExA" _
(ByVal hWnd1 AsLong, ByVal hWnd2 AsLong, ByVal lpsz1 AsString, _
ByVal lpsz2 AsString) AsLong'------------------------------------------------------PublicSub AddReference()
ThisWorkbook.VBProject.References.AddFromFile "C:\Windows\SysWOW64\UIAutomationCore.dll"EndSub'-------------------------------------------------------------'Sub baixa_titulos_CRI()
'Dimensioning the varsDim IE AsObjectDim county AsStringDim htmlDoc AsObjectDim sURL AsStringDim buttonclick AsObjectDim ShowMore AsObjectDim exportar_para_CSV AsObject'----------------'Set IE = CreateObject("internetexplorer.application")
sURL = "https://www2.cetip.com.br/TitulosCRI"With IE
.Navigate (sURL)
.Visible = TrueEndWith'I put some waits to run the webpage properly.
WaitIE2 IE, 2000Set htmlDoc = IE.Document
WaitIE2 IE, 1000'here it will press the button "enviar"Set button_send = htmlDoc.getElementById("btEnviar")
button_send.Click
WaitIE2 IE, 2000'here it will press the button "exportar para CSV"Set exportar_para_CSV = htmlDoc.getElementById("btExportarCSV")
exportar_para_CSV.Click
WaitIE2 IE, 2000'this is the solution that I found to press the button "Salvar" in IE.'I also save the directory that I wanted as default so IE save in the path properly.'I still couldnt find a solution to name of the file and to the path to save.'The solution I adapted is to list.files and the date it was saved to compare with older files (as I think you'll do it also I mentioned it here)Dim o As IUIAutomation
Dim e As IUIAutomationElement
Set o = New CUIAutomation
Dim h AsLong
h = IE.Hwnd
If h = 0ThenExitSubSet e = o.ElementFromHandle(ByVal h)
Dim iCnd As IUIAutomationCondition
Set iCnd = o.CreatePropertyCondition(UIA_NamePropertyId, "Save")
Dim Button As IUIAutomationElement
Set Button = e.FindFirst(TreeScope_Subtree, iCnd)
Dim InvokePattern As IUIAutomationInvokePattern
Set InvokePattern = Button.GetCurrentPattern(UIA_InvokePatternId)
InvokePattern.Invoke
WaitIE2 IE, 2000
IE.Quit
Set IE = NothingEndSub'-----------------------------------------------------------Sub WaitIE2(IE AsObject, Optional time AsLong = 250)
Dim i AsLongDo
Sleep time
Debug.Print CStr(i) & vbTab & "Ready: " & CStr(IE.ReadyState = 4) & _
vbCrLf & vbTab & "Busy: " & CStr(IE.Busy)
i = i + 1LoopUntil IE.ReadyState = 4OrNot IE.Busy
EndSub
I hope it helps
Best, Felipe Ribeiro
[excel] [vba]
Post a Comment for "Power Bi - Get Data From Post Request"