image download(crawling) by using winhttp in VBA

65 views Asked by At

I'm trying to download(crawling) image in VBA. I'm using "winhttp" for this.

Public Function WebFileDownload(ByVal strURL As String, ByVal strFileName As String) As Boolean
    Dim Buf() As Byte, oWinHttp

    On Error GoTo Err_Sub

    Set oWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1")

    With oWinHttp
        .Open "GET", strURL, 0
        .Send
        Buf = .ResponseBody
    End With

    Open ThisWorkbook.Path & "\" & strFileName For Binary Access Write As #1
        Put #1, , Buf
    Close #1
   
    Set oWinHttp = Nothing
    WebFileDownload = True
   
Err_Sub:
    If Err Then MsgBox Err.Description
    If Not oWinHttp Is Nothing Then Set oWinHttp = Nothing

End Function

Unfortunately, After download 20-30 files. Server change the speed very slow. I think It detect by bot. I'm using VBA, So I don't know How to avoid this. I wrote sleep time randomly, But it is not work well. Is there any tip?

0

There are 0 answers