Ir para conteúdo
Fórum Script Brasil

LeandroLazari

Membros
  • Total de itens

    4
  • Registro em

  • Última visita

Sobre LeandroLazari

LeandroLazari's Achievements

0

Reputação

  1. Boa tarde, Estou tentando fazer o download deste link "https://agentes.ons.org.br/download/operacao/hidrologia/arquivoMLTENAS_201709.pdf" Como a página é vazia e não tem desenvolvedor F12, eu tentei por SendKeys. Mas eu quando executo o código, a página abre e fecha mas não faz o download. Por que? E tem alguma outra forma de fazer este download? segue o código: Sub ENA_ONS() Dim ie As Object Set ie = CreateObject("InternetExplorer.Application") ie.Navigate "https://agentes.ons.org.br/download/operacao/hidrologia/arquivoMLTENAS_201709.pdf" ie.Visible = True Do Until (ie.readyState = 4 And Not ie.Busy) DoEvents Loop Application.SendKeys "%{S}" ie.Quit End Sub
  2. Boa tarde, Estou tentando fazer o download deste link "https://agentes.ons.org.br/download/operacao/hidrologia/arquivoMLTENAS_201709.pdf" Como a página é vazia e não tem desenvolvedor F12, eu tentei por SendKeys. Mas eu quando executo o código, a página abre e fecha mas não faz o download. Por que? E tem alguma outra forma de fazer este download? segue o código: Sub ENA_ONS() Dim ie As Object Set ie = CreateObject("InternetExplorer.Application") ie.Navigate "https://agentes.ons.org.br/download/operacao/hidrologia/arquivoMLTENAS_201709.pdf" ie.Visible = True Do Until (ie.readyState = 4 And Not ie.Busy) DoEvents Loop Application.SendKeys "%{S}" ie.Quit End Sub
  3. No rodapé deste site "http://sdro.ons.org.br/SDRO/DIARIO/index.htm" tem um ícone que faz o download de um arquivo .xls. Eu precisava clicar nele e salvar o arquivo, mas não sei como fazê-lo. Segue o código, adaptado de um outro fornecido pelo danieltakeshi, das duas formas que eu tentei fazer (a segunda marcada com *) nas duas a página abre e não acontece nada. Sub TesteBusca() Dim IE As Object Dim sWindows As Object Dim sJanelas As Object Dim sDados As String Dim doc As MSHTML.HTMLDocument Set IE = CreateObject("InternetExplorer.Application") IE.navigate "http://sdro.ons.org.br/SDRO/DIARIO/index.htm" IE.Visible = True EsperaIE IE, 2000 'Debug.Print IE.document.getElementsByTagName("frame")(1).contentDocument.getElementsByTagName("a").innerText i = 1 For Each link In IE.document.getElementsByTagName("frame")(1).contentDocument.getElementsByTagName("a") 'Debug.Print EXTRAIRELEMENTO(link.href, 8, "/") If EXTRAIRELEMENTO(link.href, 7, "/") = "DIARIO_18-03-2018.xlsx" Then i = i + 1 link.Click EsperaIE IE, 2000 If i = 2 Then Exit For End If Next link * i = 1 * For Each link In IE.document.getElementsByTagName("frame")(1).contentDocument.getElementsByTagName("a") * If link.getAttribute("scr") = "../img/exportxls.gif" Then * i = i + 1 * link.Click * EsperaIE IE, 2000 * If i = 2 Then Exit For * End If *Next link End Sub Public Sub EsperaIE(IE As Object, Optional time As Long = 250) 'Código de: https://stackoverflow.com/questions/33808000/run-time-error-91-object-variable-or-with-block-variable-not-set Dim i As Long Do Sleep time Debug.Print CStr(i) & vbTab & "Ready: " & CStr(IE.READYSTATE = 4) & _ vbCrLf & vbTab & "Busy: " & CStr(IE.Busy) i = i + 1 Loop Until IE.READYSTATE = 4 Or Not IE.Busy End Sub Function EXTRAIRELEMENTO(Txt As String, n, Separator As String) As String On Error GoTo ErrHandler: EXTRAIRELEMENTO = Split(Application.Trim(Mid(Txt, 1)), Separator)(n - 1) Exit Function ErrHandler: ' error handling code MsgBox "Erro, veriique os dados de entrada." EXTRAIRELEMENTO = CVErr(xlErrNA) On Error GoTo 0 End Function
  4. No rodapé deste site "http://sdro.ons.org.br/SDRO/DIARIO/index.htm" tem um ícone que faz o download de um arquivo .xls. Eu precisava clicar nele e salvar o arquivo, mas não sei como fazê-lo. Segue o código, adaptado de um outro fornecido pelo danieltakeshi, das duas formas que eu tentei fazer (a segunda marcada com *) nas duas a página abre e não acontece nada. Sub TesteBusca() Dim IE As Object Dim sWindows As Object Dim sJanelas As Object Dim sDados As String Dim doc As MSHTML.HTMLDocument Set IE = CreateObject("InternetExplorer.Application") IE.navigate "http://sdro.ons.org.br/SDRO/DIARIO/index.htm" IE.Visible = True EsperaIE IE, 2000 'Debug.Print IE.document.getElementsByTagName("frame")(1).contentDocument.getElementsByTagName("a").innerText i = 1 For Each link In IE.document.getElementsByTagName("frame")(1).contentDocument.getElementsByTagName("a") 'Debug.Print EXTRAIRELEMENTO(link.href, 8, "/") If EXTRAIRELEMENTO(link.href, 7, "/") = "DIARIO_18-03-2018.xlsx" Then i = i + 1 link.Click EsperaIE IE, 2000 If i = 2 Then Exit For End If Next link * i = 1 * For Each link In IE.document.getElementsByTagName("frame")(1).contentDocument.getElementsByTagName("a") * If link.getAttribute("scr") = "../img/exportxls.gif" Then * i = i + 1 * link.Click * EsperaIE IE, 2000 * If i = 2 Then Exit For * End If *Next link End Sub Public Sub EsperaIE(IE As Object, Optional time As Long = 250) 'Código de: https://stackoverflow.com/questions/33808000/run-time-error-91-object-variable-or-with-block-variable-not-set Dim i As Long Do Sleep time Debug.Print CStr(i) & vbTab & "Ready: " & CStr(IE.READYSTATE = 4) & _ vbCrLf & vbTab & "Busy: " & CStr(IE.Busy) i = i + 1 Loop Until IE.READYSTATE = 4 Or Not IE.Busy End Sub Function EXTRAIRELEMENTO(Txt As String, n, Separator As String) As String On Error GoTo ErrHandler: EXTRAIRELEMENTO = Split(Application.Trim(Mid(Txt, 1)), Separator)(n - 1) Exit Function ErrHandler: ' error handling code MsgBox "Erro, veriique os dados de entrada." EXTRAIRELEMENTO = CVErr(xlErrNA) On Error GoTo 0 End Function
×
×
  • Criar Novo...