0

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?

Tom Brunberg
  • 20,312
  • 8
  • 37
  • 54
zerom
  • 3
  • 3
  • Code is divied ;; It isn't edited 'code'.. – zerom Jan 10 '23 at 11:13
  • 2
    If the slow down is controlled by the server, there's not much you can do except obey its rules on download limits, repeat frequency and such. There is no way to avoid this. – Tom Brunberg Jan 10 '23 at 12:04

0 Answers0