Condividi:        

[Macro]Importare dati da URL attivati con Javascript

Vuoi potenziare i tuoi documenti Word? Non sai come si fa una macro in Excel? Devi creare una presentazione in PowerPoint?
Oppure sei passato a OpenOffice e non sei sicuro di come lavorare al meglio?

Moderatori: Anthony47, Flash30005

Re: [Macro]Importare dati da URL attivati con Javascript

Postdi Anthony47 » 02/04/18 22:55

Oramai dovresti pero' sapere come modificare il codice per catturare piu' /meno /diverse cose...
Ho modificato il precedente ciclo For Each myItm In mycoll /Next myItm per prelevare anche lega e turno; il nuovo codice completo:
Codice: Seleziona tutto
Sub BetRadarWTurno()
'Vedi http://www.pc-facile.com/forum/viewtopic.php?f=26&t=109246&p=643157
'''Application.Calculation = xlCalculationManual
Dim IE As Object
Dim myURL As String, myHL As String
Dim mySplit, tDtD, tRtR
Dim I As Long, J As Long
Dim Fl1st As Boolean, myH2Coll, CI As Long, myItm

myURL = "http://stats.betradar.com/s4/?clientid=5&language=it#2_1,3_17,22_1,5_41264,9_fixtures,231_full,23_1"
myHL = "http://stats.betradar.com/s4/?clientid=5&language=it#2_1,3_17,22_1,5_41264,9_match,8_#####,178_2055,7_2061"

Set IE = CreateObject("InternetExplorer.Application")

With IE
    .navigate myURL
    .Visible = True
    Do While .Busy: DoEvents: Loop
    Do While .readyState <> 4: DoEvents: Loop
End With
'
myStart = Timer
Do
    DoEvents
    If Timer > myStart + 2 Or Timer < myStart Then Exit Do
Loop

I = 1
Worksheets("Foglio1").Activate
Range("A:G").Clear
Set mycoll = IE.document.getElementsByTagName("TABLE")
Set myH2Coll = mycoll(0).parentElement.getElementsByTagName("h2")
For CI = 0 To mycoll.Length - 1
    If CI = 0 Then
        If myH2Coll.Length >= 1 Then
            Cells(I + 1, 1) = myH2Coll(CI).innerText
            I = I + 1
        End If
    End If
    If CI <= myH2Coll.Length Then Cells(I + 1, 1) = myH2Coll(CI + 1).innerText: I = I + 1
    Set myItm = mycoll(CI)
    For Each tRtR In myItm.Rows
        For Each tDtD In tRtR.Cells
            Cells(I + 1, J + 1) = tDtD.innerText
'Per hLink>>:
                Set piPP = tDtD.getElementsByTagName("a")
                If piPP.Length > 0 Then
                mySplit = Split(piPP(0).href, ",", , vbTextCompare)
                    If UBound(mySplit) = 2 Then
                        ActiveSheet.Hyperlinks.Add Anchor:=Cells(I + 1, J + 1), Address:= _
                        Replace(myHL, "#####", Trim(mySplit(1)), , , vbTextCompare), TextToDisplay:=Cells(I + 1, J + 1).Value
                    End If
                End If
'<< End hLink
            J = J + 1
        Next tDtD
        I = I + 1: J = 0
    Next tRtR
    I = I + 1
Next CI
'
IE.Quit
Set IE = Nothing
Calculate
End Sub

Fai sapere...
Avatar utente
Anthony47
Moderatore
 
Post: 19228
Iscritto il: 21/03/06 16:03
Località: Ivrea

Sponsor
 

Re: [Macro]Importare dati da URL attivati con Javascript

Postdi daviluc61 » 03/04/18 05:28

Ok risolto. Grazie come sempre
daviluc61
Utente Junior
 
Post: 15
Iscritto il: 31/12/17 11:33

Precedente

Torna a Applicazioni Office Windows


Topic correlati a "[Macro]Importare dati da URL attivati con Javascript":


Chi c’è in linea

Visitano il forum: Nessuno e 89 ospiti

cron