HTML problem with VBA



  • HTML problem with VBA
    di Gianna (utente non iscritto) data: 27/02/2014 10:55:16

    Hi, I'm Gianna and first of all SORRY FOR MY ENGLISH!

    I need your help to solve a big (to me!) problem.

    Monthly I need to download a huge quantity of electrical data from Enel Distribuzione page.

    (there is a security problem the first time but it is safe!!!)

    and I'm trying to automatically download them with a VBA macro but it doesn't work.

    Please can you help me?

    Gianna
     
    Sub Enel()
    Dim HTMLDoc As HTMLDocument
    Dim oBrowser As InternetExplorer
    Dim oHTML_Element As IHTMLElement
    Dim sURL As String
    
    On Error GoTo Err_Clear
    sURL = "wdmdd.enel.it/ azienda /index_azienda .asp"
    Set oBrowser = New InternetExplorer
    oBrowser.Silent = True
    oBrowser.timeout = 60
    oBrowser.navigate sURL
    oBrowser.Visible = True
    
    Do
    ' Wait till the Browser is loaded
    Loop Until oBrowser.readyState = READYSTATE_COMPLETE
    
    Set HTMLDoc = oBrowser.document
    
    
    HTMLDoc.document.all.UserName.Value = "IT001E0038"
    HTMLDoc.document.all.Password.Value = "Eseio12"
    
    
    For Each oHTML_Element In HTMLDoc.getElementsByTagName("input")
    If oHTML_Element.Name = "Password" Then oHTML_Element.Click: Exit For
    Next
    
    ' oBrowser.Refresh ' Refresh If Needed
    Err_Clear:
    If Err <> 0 Then
    Err.Clear
    Resume Next
    End If
    
    End Sub
    
    



  • di Gianna (utente non iscritto) data: 27/02/2014 11:00:49

    Scusate ho allegato la discussione da un sito inglese.

    In pratica vi chiedo aiuto perchè sulla pagina per scaricare i dati di prelievo energia di Enel Distribuzione non riesco ad inserire username e password.
    Sa analizzo la pagina html vedo sia Username che Password ma non riesco ascriverci sopra...
    Mi potete aiutare?

    Grazie Gianna



  • di Grograman (utente non iscritto) data: 27/02/2014 13:11:54

    Ciao Gina non ti preoccupare per l'inglese, si capisce perfettamente!



  • di vmontal data: 27/02/2014 14:14:02

    Prova con questa procedura:
    i nomi dei campi "ssousername" e "password" li ho ricavati visualizzando il codice HTML (click dx) della pagina di accesso;
    URL_Download è l'indirizzo della pagina da cui faccio lo scarico del file
     
    Sub Scarica_Lista()
        On Error GoTo Scarica_Err
        
        Dim IE As Object
        Dim myUtente As String, myPassword As String
        Dim Giorno, Mese, Anno As Integer
        Dim s_Giorno, s_Mese, s_Anno As String
        
        'Credenziali di accesso
        myUtente = "nomeutente"
        myPassword = "password"
        
        'Giorno, Mese, Anno attuale
        Giorno = Day(Now()):  s_Giorno = IIf(Giorno < 10, "0" & Trim(str(Giorno)), Trim(str(Giorno)))
        Mese = Month(Now()):  s_Mese = IIf(Mese < 10, "0" & Trim(str(Mese)), Trim(str(Mese)))
        Anno = Year(Now()):  s_Anno = Trim(str(Anno))
      
        Set IE = CreateObject("InternetExplorer.Application")
        
        IE.Navigate URL_Login
        
        Do While IE.Busy Or IE.ReadyState <> 4
            DoEvents
        Loop
        
        IE.Document.Forms(0).Item("ssousername").Value = myUtente
        IE.Document.Forms(0).Item("password").Value = myPassword
        IE.Document.Forms(0).submit
        
        Do While IE.Busy Or IE.ReadyState <> 4
            DoEvents
        Loop
      
        IE.Navigate URL_Download
        
        Do While IE.Busy Or IE.ReadyState <> 4
            DoEvents
        Loop
        
        IE.Navigate URL_Logout
        
        Do While IE.Busy Or IE.ReadyState <> 4
            DoEvents
        Loop
        
        IE.Application.Quit
        
        Set IE = Nothing
        
    Scarica_Exit:
        
        Exit Sub
    
    Scarica_Err:
        MsgBox Err.Description
        Resume Scarica_Exit
    
    End Sub
    



  • di g (utente non iscritto) data: 27/02/2014 14:56:31

    Non funziona.
    Se sul sito h t t p s :""wdmdd. enel.it/azienda /curve_azienda. asp ispeziono gli elementi Username e Password (cambia i due apici con \ e togli gli spazi) ottengo questo:





    ma

    HTMLDoc.document.all.UserName.Value = "IT001E0038"
    HTMLDoc.document.all.Password.Value = "Eseio12"

    non funzionano..

    sbaglio sintassi?

    PS

    Sono due giorni che lavoro con HTML portate pazienza....



  • di Gianna (utente non iscritto) data: 27/02/2014 14:58:37

    Per vederli basta fare click con tasto di destra - ispeziona elemento sui due campi........



  • di g (utente non iscritto) data: 27/02/2014 15:56:49

    Mi rispondono:

    It looks like the username section is in a iframe... You'll probably have to grab the document to that URL instead.

    ma non ho idea di cosa dovrei fare.....



  • di Zer0Kelvin data: 28/02/2014 22:29:40

    Ciao.
    Ti rispondo ma forse dico cavolate.
    Un frame non è altro che un'area della pagina web all'interno della quale viene visualizzata un'altra pagina web.
    A te servirebbe l'indirizzo della pagina web visualizzata nel frame, ed è quello che devi cercare.



  • di Zer0Kelvin data: 28/02/2014 22:34:07

    prova a cercare nel codice html la stringa"frameset"; l'eventuale url che segue deve essere l'indirizzo che ti serve.



  • di giannapinato data: 28/02/2014 22:41:07

    Grazie proverò'

    Gianna