IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB 6 et antérieur Discussion :

Télécharger pages Web


Sujet :

VB 6 et antérieur

  1. #1
    Futur Membre du Club
    Inscrit en
    Mai 2005
    Messages
    3
    Détails du profil
    Informations forums :
    Inscription : Mai 2005
    Messages : 3
    Par défaut Télécharger pages Web
    Bonjour,

    Est-ce que quelqu'un s'y connait en controile Winsock, ou Inet. En fait je cherche à télécharger plusieurs pages Web, via un programme en Visual Basic. J'arrive déja à en télécharger, mais seulement une par une.
    En fait je voudrais arriver à télécharger plusieurs à la suite de cette manière-ci :
    http://www.website.com/pages/001.html
    http://www.website.com/pages/002.html
    http://www.website.com/pages/003.html
    etc...
    Et je voudrais remplacer les noms de pages (001, 002, 003, etc...) par des variables.
    Merci d'avance

  2. #2
    Expert éminent


    Profil pro
    Inscrit en
    Juin 2003
    Messages
    14 008
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 14 008
    Par défaut
    c'est quoi ton code pour télécharger... il suffit de faire une boucle et de modifier le nom de la page à atteindre...( ? navigate...)


  3. #3
    Futur Membre du Club
    Inscrit en
    Mai 2005
    Messages
    3
    Détails du profil
    Informations forums :
    Inscription : Mai 2005
    Messages : 3
    Par défaut
    Voici mon bout de code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    Private Sub btnStartDL_Click()
        Inet1.RequestTimeout = Timeout 'set timeout
        ProgressBar1.Max = 1024 
        Destination = App.Path & "\file.html" 'set destination file
        Label1.Caption = "Establishing connection..."
        Inet1.Execute "http://www.google.com", "GET" 'Start the download
    End Sub
    En fait g deja essayé avec une boucl emais ça enregistre sur le meme fichier à chaque fois. J'ai pa senvie d'essayet plusieurs controles Inet, juste un seul.

  4. #4
    Expert éminent


    Profil pro
    Inscrit en
    Juin 2003
    Messages
    14 008
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 14 008
    Par défaut
    Citation Envoyé par shomacdo
    Voici mon bout de code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    Private Sub btnStartDL_Click()
        Inet1.RequestTimeout = Timeout 'set timeout
        ProgressBar1.Max = 1024 
        Destination = App.Path & "\file.html" 'set destination file
        Label1.Caption = "Establishing connection..."
        Inet1.Execute "http://www.google.com", "GET" 'Start the download
    End Sub
    En fait g deja essayé avec une boucl emais ça enregistre sur le meme fichier à chaque fois. J'ai pa senvie d'essayet plusieurs controles Inet, juste un seul.
    tu change bien le nom de fichier destination à chaque fois ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     App.Path & "\file.html" 'set destination file

    un peu dans le genre :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Private Sub btnStartDL_Click()
     for i = 1 to 3
        Inet1.RequestTimeout = Timeout 'set timeout
        ProgressBar1.Max = 1024 
        Destination = App.Path & "\file" & i & ".html" 'set destination file
        Label1.Caption = "Establishing connection..."
        Inet1.Execute "http://www.website.com/pages/00" & i & ".html"
    , "GET" 'Start the download
    next
    End Sub

  5. #5
    Futur Membre du Club
    Inscrit en
    Mai 2005
    Messages
    3
    Détails du profil
    Informations forums :
    Inscription : Mai 2005
    Messages : 3
    Par défaut
    En fait voici le code en entier que j'utlise :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    Option Explicit
     
    'downloads an (binary)file over the HTTP-protocol and saves it to a file
     
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
        lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long) 'used for direct memory copy
     
     
    Const Timeout As Long = 60 'Timeout, if no connection can be established (in seconds)
    Dim file() As Byte, Destination As String 'Byte-Array containing current file-contents; Destination file on the harddisk
    Dim LastSizeCheck As Long, LastSize As Long 'Data needed for speed-status
     
    Private Sub btnStartDL_Click()
    Dim index            As Integer
    Dim tableau(1 To 5)  As String
     
    tableau(1) = "0139-TOM-13:34:58"
    tableau(2) = "0139-PQR-13:03:16"
    tableau(3) = "0137-JOHN-16:00:50"
    tableau(4) = "0137-BOB-15:56:55"
    tableau(5) = "0137-BOB-15:41:48"
     
    For index = 1 To 5
        Inet1.RequestTimeout = Timeout 'set timeout
        ProgressBar1.Max = 1024 '--- here you must fill in the expected file size (in KBs), for using the progressbar...
        Destination = App.Path & "\file" & index & ".html" 'set destination file
        Label1.Caption = "Establishing connection..."
        Inet1.Execute "http://10.101.55.95/cgi-bin/ProcSummary?VIEW&" & tableau(index), "GET"  'Start the download of the specified file
    Next index
     
    End Sub
     
    'Determines the UBound of the "file"-Array. If the Array is "Empty" ("Erase file"), it returns -1
    Private Function SafeUBoundFile() As Long
        On Error GoTo erro
        SafeUBoundFile = UBound(file)
        Exit Function
    erro:
        SafeUBoundFile = -1
    End Function
     
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
        Inet1.Cancel 'cancel on exit
    End Sub
     
    Private Sub INet1_StateChanged(ByVal State As Integer)
        Static inProc As Boolean
        If Not inProc Then 'only execute this procedure, if it is the first call (DoEvents in this sub may call this event frequently
            inProc = True
            Debug.Print Timer, State
            Select Case State
                Case icResponseReceived 'Received something
                    Dim vtData() As Byte 'Current Chunk
                    Label1.Caption = "Downloading " & Inet1.URL & "..."
     
                    Do While Inet1.StillExecuting
                        DoEvents
                    Loop
                    Do
                        DoEvents
                        vtData = Inet1.GetChunk(256, 1)
                        If UBound(vtData) = -1 Then Exit Do 'exit loop, if no Chunk could received
                        ReDim Preserve file(SafeUBoundFile + UBound(vtData) + 1) 'enlarge file-array
                        CopyMemory file(UBound(file) - UBound(vtData)), vtData(0), UBound(vtData) + 1 'copy received Chunk to the file-array
                        If UBound(vtData) <> 255 Then Exit Do 'if the length of the chunk is not 255, then it must be the last chunk of the file
     
                        Dim tmp As Long
                        tmp = UBound(file) / 1024
                        If tmp > ProgressBar1.Max Then tmp = ProgressBar1.Max 'if KBs is higher then ProgressBar1.Maxy then truncated
                        ProgressBar1.Value = tmp 'update ProgressBar1
                    Loop
     
                    Label1.Caption = "Download complete."
                    MsgBox "Download complete."
     
                    Inet1.Cancel
     
                    Open Destination For Binary As #1 'Write file-array to destination-file
                    Put #1, , file
                    Close #1
                    Erase file 'free file-array
            End Select
            inProc = False
        End If
    End Sub
     
    'Updates the status. Think about it....
    Private Sub Timer1_Timer()
        Label2.Caption = Format(SafeUBoundFile / 1024, "#,##0.00 KB") & " @ " & _
            Format((SafeUBoundFile - LastSize) / 1024 / (Timer - LastSizeCheck / 1000), "#,##0.00 KB/s")
        LastSizeCheck = Timer * 1000
        LastSize = SafeUBoundFile
    End Sub

    *********************************
    Mais apparemment lorsque l'on commence le téléchargement d'une page, le programme continue à tourner, sans que l'actuel téléchargement soit fini. De ce fait, j'ai un message d'erreur me disant "Still executing Last request", en gros "je suis déja en train de faire une requete et j'ai pas fini" (enfin je pense). Donc je voudrais arriver à lui dire que tant qu'il a pas fini un téléchargement, il commence pas l'autre. Si tu vois ce que je veux dire.
    Ou sinon, si toi tu arrives à faire cette manip' par un autre moyen, n'hésite pas à me le faire savoir.

    Merci beaucoup d'avance

  6. #6
    Expert éminent


    Profil pro
    Inscrit en
    Juin 2003
    Messages
    14 008
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 14 008
    Par défaut
    il te faut synchroniser ta boucle for ... et la fin du traitement dans la fonction stateChange ....

    par exemple
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
     
    Option Explicit 
    dim bSuivant as boolean 'BIT DE SYNCHRO ... PASSAGE FICHIER SUIVANT
     
    'downloads an (binary)file over the HTTP-protocol and saves it to a file 
     
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _ 
    lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long) 'used for direct memory copy 
     
     
    Const Timeout As Long = 60 'Timeout, if no connection can be established (in seconds) 
    Dim file() As Byte, Destination As String 'Byte-Array containing current file-contents; Destination file on the harddisk 
    Dim LastSizeCheck As Long, LastSize As Long 'Data needed for speed-status 
     
    Private Sub btnStartDL_Click() 
    Dim index As Integer 
    Dim tableau(1 To 5) As String 
     
    tableau(1) = "0139-TOM-13:34:58" 
    tableau(2) = "0139-PQR-13:03:16" 
    tableau(3) = "0137-JOHN-16:00:50" 
    tableau(4) = "0137-BOB-15:56:55" 
    tableau(5) = "0137-BOB-15:41:48" 
     
    For index = 1 To 5 
    bSuivant = false
    Inet1.RequestTimeout = Timeout 'set timeout 
    ProgressBar1.Max = 1024 '--- here you must fill in the expected file size (in KBs), for using the progressbar... 
    Destination = App.Path & "\file" & index & ".html" 'set destination file 
    Label1.Caption = "Establishing connection..." 
    Inet1.Execute "http://10.101.55.95/cgi-bin/ProcSummary?VIEW&" & tableau(index), "GET" 'Start the download of the specified file 
    Next index 
    While NOt bSuivant 'Attente passage fichier suivant..
     DoEvents
    Wend
     
    End Sub 
     
    'Determines the UBound of the "file"-Array. If the Array is "Empty" ("Erase file"), it returns -1 
    Private Function SafeUBoundFile() As Long 
    On Error GoTo erro 
    SafeUBoundFile = UBound(file) 
    Exit Function 
    erro: 
    SafeUBoundFile = -1 
    End Function 
     
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) 
    Inet1.Cancel 'cancel on exit 
    End Sub 
     
    Private Sub INet1_StateChanged(ByVal State As Integer) 
    Static inProc As Boolean 
    If Not inProc Then 'only execute this procedure, if it is the first call (DoEvents in this sub may call this event frequently 
    inProc = True 
    Debug.Print Timer, State 
    Select Case State 
    Case icResponseReceived 'Received something 
    Dim vtData() As Byte 'Current Chunk 
    Label1.Caption = "Downloading " & Inet1.URL & "..." 
     
    Do While Inet1.StillExecuting 
    DoEvents 
    Loop 
    Do 
    DoEvents 
    vtData = Inet1.GetChunk(256, 1) 
    If UBound(vtData) = -1 Then Exit Do 'exit loop, if no Chunk could received 
    ReDim Preserve file(SafeUBoundFile + UBound(vtData) + 1) 'enlarge file-array 
    CopyMemory file(UBound(file) - UBound(vtData)), vtData(0), UBound(vtData) + 1 'copy received Chunk to the file-array 
    If UBound(vtData) <> 255 Then Exit Do 'if the length of the chunk is not 255, then it must be the last chunk of the file 
     
    Dim tmp As Long 
    tmp = UBound(file) / 1024 
    If tmp > ProgressBar1.Max Then tmp = ProgressBar1.Max 'if KBs is higher then ProgressBar1.Maxy then truncated 
    ProgressBar1.Value = tmp 'update ProgressBar1 
    Loop 
     
    Label1.Caption = "Download complete." 
    MsgBox "Download complete." 
     
    Inet1.Cancel 
     
    Open Destination For Binary As #1 'Write file-array to destination-file 
    Put #1, , file 
    Close #1 
    Erase file 'free file-array 
    End Select 
    inProc = False 
    End If 
    bSuivant = true 'AUTORISE PASSAGE FICHIER SUIVANT
    End Sub 
     
    'Updates the status. Think about it.... 
    Private Sub Timer1_Timer() 
    Label2.Caption = Format(SafeUBoundFile / 1024, "#,##0.00 KB") & " @ " & _ 
    Format((SafeUBoundFile - LastSize) / 1024 / (Timer - LastSizeCheck / 1000), "#,##0.00 KB/s") 
    LastSizeCheck = Timer * 1000 
    LastSize = SafeUBoundFile 
    End Sub
    .. reste peu-être à voir le cas du time-out histoire de ne pas être bloqué dans boucle attente suivant...

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 3
    Dernier message: 21/08/2007, 16h24
  2. Télécharger le code source d'une page web en C
    Par DooSquare dans le forum Bibliothèques
    Réponses: 21
    Dernier message: 28/06/2007, 17h24
  3. Télécharger page web, lire et écrire
    Par misa dans le forum Général JavaScript
    Réponses: 6
    Dernier message: 26/04/2007, 08h34
  4. [VB]télécharger une image d'une page web
    Par thorgal85 dans le forum VB 6 et antérieur
    Réponses: 12
    Dernier message: 12/03/2006, 16h42
  5. Réponses: 2
    Dernier message: 19/12/2005, 13h15

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo