• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Extracting picture from a webpage - doesn't work in a few cases


Chiriho, when you have time, thanks to confirm on both computers
POST request can't work without "User-Agent" header …
 
I met same issue with GET request with a laptop under Windows 8
and my DocOpen procedure failed too !
But as original request within webbrowser inpector tool is a GET type,
I tried all headers but failed.
And I saw the light, made a mod and success, my entire bad :
XMLrequest is not the standard library used by webbrowsers !

So last but not least, this is the new GET request but as a function :​
Code:
Function RequestDownload(URL$, FILE$) As Boolean
                     Dim B() As Byte, F%
    With CreateObject("WinHttp.WinHttpRequest.5.1")
        .Open "GET", URL, False
        .setRequestHeader "DNT", "1"
        On Error GoTo Fin
        .send
     If .Status = 200 Then
         B = .responseBody
         F = FreeFile(1)
         Open FILE For Binary As #F
         Put #F, , B
         Close #F
         RequestDownload = True
     End If
Fin:
    End With
End Function


Sub Demo()
    SRC$ = "http://fr.louisvuitton.com/images/is/image/lv/1/PP_VP_AS/louis-vuitton--M41746_PM2_Front view.jpg"
    LFN$ = "D:\Tests\louis-vuitton-M41746_PM2_Front view.jpg"
    If RequestDownload(SRC, LFN) Then
        Cells(5).Select
        ActiveSheet.Pictures.Insert LFN
    End If
End Sub
I hope this time your tests on both computers will be successful too …
 
A reminder for this kind of stuff : not be too lazy
with less characters to enter for a non standard library ! :DD

I usually prefer to use XML library easier in case of any error …

OK, this thread is solved !
 
Back
Top