Condividi:        

Scarico dati da sito prosoccer

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

Scarico dati da sito prosoccer

Postdi apocrimata75 » 26/02/14 15:21

Codice: Seleziona tutto
Sub Macro15()
Sheets("forebet").Select
Range("a2:o2000").Select
    Selection.ClearContents

    Application.ScreenUpdating = False
   
    Range("A2").Select
    With Selection.QueryTable
        .Connection = _
        "URL;http://www.prosoccer.gr/" & Range("b1") & "/" & Range("c1") & "/" & "soccer-predictions-" & Range("b1") & "-" & Range(c1) & "-" & Range(d1) & ".html"
        .WebSelectionType = xlSpecifiedTables
        .WebFormatting = xlWebFormattingNone
        .WebTables = "4"
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
       
   
SendKeys "{F5}", True
        SendKeys "{ENTER}", True

Sheets("Foglio Proiezioni").Select
    Range("a6").Select

   End Sub


Avevo predisposto questa macro con la speranza che scaricasse i dati dal sito

http://www.prosoccer.gr/en/2014/02/soccer-predictions-2014-02-26.html

nelle celle B1, C1 e D1 ho inseritola formula
Codice: Seleziona tutto
=oggi()
formattando rispettivamente le stesse con aaaa, mm e gg

ma invece di scaricare restituisce l'errore "errore di run-time '1004' metodo range dell'oggetto _ global non riuscito.

Dove sbaglio?

Purtroppo l'URL cambia in base alla data.
Windows 7 - Office 2010
apocrimata75
Utente Senior
 
Post: 189
Iscritto il: 28/05/11 13:22

Sponsor
 

Re: Scarico dati da sito prosoccer

Postdi Anthony47 » 26/02/14 17:49

Metti Oggi() in B1 solamente, poi userai
Format(Range("B1"), "yyyy") per avere l' anno
Format(Range("B1"), "mm") per avere il mese
Format(Range("B1"), "yyyy-mm-dd") per avere es 2014-02-26

Ciao
Avatar utente
Anthony47
Moderatore
 
Post: 19196
Iscritto il: 21/03/06 16:03
Località: Ivrea

Re: Scarico dati da sito prosoccer

Postdi ricky53 » 26/02/14 17:49

Ciao,
ecco un esempio di url
http://www.prosoccer.gr/en/2014/02/socc ... 02-26.html

Tu in
"URL;http://www.prosoccer.gr/" & Range("b1") & "/" & Range("c1") & "/" & "soccer-predictions-" & Range("b1") & "-" & Range(c1) & "-" & Range(d1) & ".html"
non hai messo:
1. l'anno ed il mese dopo "/en/"
2. la data dopo "predictions"
3. mancano degli apici a Range

prova con
Codice: Seleziona tutto
"URL;http://www.prosoccer.gr/" & Year(Range("B1")) & "/" & Format(Range("B1"),"mm") & "/" & "soccer-predictions-" & Year(Range("B1")) & "-" & Format(Range("B1"), "mm") & "-" & Format(Range("B1"), "dd") & ".html"


Basta una sola cella che contenga una data ed ho utilizzato solo la "B1"
Ho scritto senza provare .. spero che la sintassi sia giusta
Prova ...


EDIT:
ho appena visto che Anthony ti aveva già risposto nello stesso minuto !!!
Dice il vecchio saggio provare e riprovare è l'unica strada per imparare

Più chiara è la vostra spiegazione
Più immediata sarà la nostra soluzione


. . . . . . . . . .
S.O. W10; Office 2003-10-13-16-19
Avatar utente
ricky53
Utente Senior
 
Post: 4565
Iscritto il: 11/04/09 19:29
Località: Italia

Re: Scarico dati da sito prosoccer

Postdi apocrimata75 » 26/02/14 23:27

Ho risolto così, grazie a voi
Codice: Seleziona tutto
Sub Macro15()
Sheets("forebet").Select
Range("a2:o2000").Select
    Selection.ClearContents

    Application.ScreenUpdating = False
   
    Range("A2").Select
    With Selection.QueryTable
        .Connection = _
        "URL;http://www.prosoccer.gr/en/" & Year(Range("B1")) & "/" & Format(Range("B1"), "mm") & "/" & "soccer-predictions-" & Year(Range("B1")) & "-" & Format(Range("B1"), "mm") & "-" & Format(Range("B1"), "dd") & ".html"
        .WebSelectionType = xlSpecifiedTables
        .WebFormatting = xlWebFormattingNone
        .WebTables = "7"
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
       
   
SendKeys "{F5}", True
        SendKeys "{ENTER}", True

Sheets("Foglio Proiezioni").Select
    Range("a6").Select

   End Sub


ma invece delle cifre compaiono lettere, invece di 40-28-32 estrae MB-FU-LF
Windows 7 - Office 2010
apocrimata75
Utente Senior
 
Post: 189
Iscritto il: 28/05/11 13:22

Re: Scarico dati da sito prosoccer

Postdi ricky53 » 27/02/14 00:44

Ciao,
si anche a me, in alcune righe non vi sono i tre gruppi di numeri ma due lettere per cella ... strano.
Dice il vecchio saggio provare e riprovare è l'unica strada per imparare

Più chiara è la vostra spiegazione
Più immediata sarà la nostra soluzione


. . . . . . . . . .
S.O. W10; Office 2003-10-13-16-19
Avatar utente
ricky53
Utente Senior
 
Post: 4565
Iscritto il: 11/04/09 19:29
Località: Italia

Re: Scarico dati da sito prosoccer

Postdi Anthony47 » 27/02/14 02:24

Diciamo che i gestori del sito preferiscono che i loro dati rimangano visualizzabili ma non gestibili facilmente al di fuori del loro ambiente...
Se si guarda il sorgente e' evidente che nelle caselle sotto OUTCOME PREDICTION(%) ci sono scritte stringhe come quelle che importi (es " MB", " FU", " LF" e cosi' via); invece a video si visualizza una immagine impostata nel foglio di stile css, corrispondente all' url http://www.prosoccer.gr/imgs/num9_13.png
L' immagine viene fatta "scorrere" in verticale in modo che nella casella del <td> emerga il numero voluto; es per il n° 5 si usa background-position: 0px -65px; per il n° 6 invece background-position: 0px -78px; il n° 7 invece background-position: 0px -91px; e cosi' analogamente per comporre gli altri numeri.

Diciamo che si puo' decodificare il numero lavorando sul codice html, ma se l' hanno fatta cosi' e' perche' non vogliono farsi "intercettare", e probabilmente cambieranno foglio stile e sorgente periodicamente, con la certezza che il codice di oggi non andra' bene domani.
Quindi a scopo puramente ludico sottopongo questo codice che estrae le colonne 1, x, 2 relative all' outcome prediction(%).
Codice: Seleziona tutto
Sub pipp()
Dim IE As Object, myVal As String
'
myurl = "http://www.prosoccer.gr/en/2014/02/soccer-predictions-2014-02-26.html"
'
If IE Is Nothing Then Set IE = CreateObject("InternetExplorer.Application")
'Set IE = CreateObject("InternetExplorer.Application")

Sheets("Foglio4").Select
Sheets("Foglio4").Range("A:Z").ClearContents
   
On Error GoTo QuitIE
With IE
    .navigate myurl
    .Visible = True
    Do While .Busy: DoEvents: Loop    'Attesa not busy
    Do While .ReadyState <> 4: DoEvents: Loop 'Attesa documento
End With

myStart = Timer
Do
    DoEvents
    If Timer > myStart + 1 Or Timer < myStart Then Exit Do
Loop
'
Set myColl = IE.document.getElementbyid("anyid") 'IE.Document.GetElementsByTagName("table")
'
jj = 2
For Each trtr In myColl.Rows
    kk = 1
    For Each tdtd In trtr.Cells
        If Left(tdtd.classname, 3) = "pli" Then
            Set my2Coll = tdtd.getelementsbytagname("span")
            For Each mySp In my2Coll
                myVal = myVal & Right(mySp.classname, 1)
            Next mySp
            Cells(jj, kk) = myVal
            myVal = ""
           
        Else
            Cells(jj, kk).Value = tdtd.innertext
            zzzz = tdtd.innertext
        End If
        kk = kk + 1
    Next tdtd
jj = jj + 1
Next trtr
QuitIE:
    IE.Quit
    Set IE = Nothing
End Sub

Lavora sul Foglio4 del vostro file (createlo prima di lanciare la macro), foglio che sara' azzerato senza nessun preavviso.
Le colonne K, L e O devono essere preventivamente formattate "Testo".

La colonna TIPS lavora su un' immagine piu' articolata (http://www.prosoccer.gr/imgs/tips.png), potrebbe anche essa essere ricostruita o graficamente oppure creando una tabella di equivalenze tra le classnames e il significato; oppure guardiamo solo i primi 2 digit della sigla che compare in colonna.

Ciao
Avatar utente
Anthony47
Moderatore
 
Post: 19196
Iscritto il: 21/03/06 16:03
Località: Ivrea

Re: Scarico dati da sito prosoccer

Postdi apocrimata75 » 27/02/14 19:57

Spettacolare è a dir poco. Grazie mille.
Windows 7 - Office 2010
apocrimata75
Utente Senior
 
Post: 189
Iscritto il: 28/05/11 13:22

Re: Scarico dati da sito prosoccer

Postdi apocrimata75 » 28/02/14 00:11

Codice: Seleziona tutto
Sub Macro17()



   Dim IE As Object, myVal As String
   
        myurl = "http://www.prosoccer.gr/en/" & Year(Range("B1")) & "/" & Format(Range("B1"), "mm") & "/" & "soccer-predictions-" & Year(Range("B1")) & "-" & Format(Range("B1"), "mm") & "-" & Format(Range("B1"), "dd") & ".html"
       
       If IE Is Nothing Then Set IE = CreateObject("InternetExplorer.Application")
'Set IE = CreateObject("InternetExplorer.Application")

Sheets("forebet").Select
    Range("a2:o2000").Select
    Selection.ClearContents
   
    On Error GoTo QuitIE
With IE
    .navigate myurl
    .Visible = True
    Do While .Busy: DoEvents: Loop    'Attesa not busy
    Do While .readyState <> 4: DoEvents: Loop 'Attesa documento
End With

myStart = Timer
Do
    DoEvents
    If Timer > myStart + 1 Or Timer < myStart Then Exit Do
Loop
'
Set myColl = IE.document.getElementById("anyid") 'IE.Document.GetElementsByTagName("table")
'
jj = 2
For Each trtr In myColl.Rows
    kk = 1
    For Each tdtd In trtr.Cells
        If Left(tdtd.className, 3) = "pli" Then
            Set my2Coll = tdtd.getElementsByTagName("span")
            For Each mySp In my2Coll
                myVal = myVal & Right(mySp.className, 1)
            Next mySp
            Cells(jj, kk) = myVal
            myVal = ""
           
        Else
            Cells(jj, kk).Value = tdtd.innerText
            zzzz = tdtd.innerText
        End If
        kk = kk + 1
    Next tdtd
jj = jj + 1
Next trtr
QuitIE:
    IE.Quit
    Set IE = Nothing

   
        SendKeys "{ENTER}", True

Sheets("Foglio Proiezioni").Select
    Range("a6").Select

   End Sub


Macro finale con le dovute modifiche.

Grazie ancora
Windows 7 - Office 2010
apocrimata75
Utente Senior
 
Post: 189
Iscritto il: 28/05/11 13:22


Torna a Applicazioni Office Windows


Topic correlati a "Scarico dati da sito prosoccer":


Chi c’è in linea

Visitano il forum: Nessuno e 66 ospiti