Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Save image files from web page
Message
From
25/10/2006 08:59:57
 
General information
Forum:
Visual FoxPro
Category:
Internet applications
Environment versions
Visual FoxPro:
VFP 8
Miscellaneous
Thread ID:
01164249
Message ID:
01164326
Views:
16
Rick,


Thanks a bunch!!! That was exactly what I needed!

Greg

>Don't use teh Internet Transfer control... You can use XmlHttp or WinHttp (or as I did in my original code for this wwHTTP from West Wind Internet Protocols). Here's the code with using XmlHttp:
>
>
>FUNCTION SaveAllImages
>LPARAMETER loDocument, lcRelFolder
>
>IF !DIRECTORY(lcRelFolder)
>  MD (lcRelFolder)
>ENDIF
>
>* loHttp = CREATEOBJECT("wwHTTP")
>
>loImages = loDocument.Images
>FOR EACH loImage in loImages
>  lcSource = loImage.src
>  * lcImgBinary = loHttp.HttpGet(lcSource)
>  lcImgBinary = XmlHttp(lcSource)
>  STRTOFILE(lcImgBinary,lcRelFolder + "\" + JustFname(lcSource) )
>ENDFOR
>
>************************************************************************
>FUNCTION XMLHttp
>****************************************
>***  Function: Returns HTTP response from a URL as a string
>***      Pass:
>***    Return:
>************************************************************************
>LPARAMETERS lcUrl, lcPostBuffer, lcUsername, lcPassword, lcContentType
>LOCAL lcVerb, llResult, lcResponse
>
>IF EMPTY(lcPostBuffer)
>   lcPostBuffer = ""
>ENDIF
>IF EMPTY(lcUsername)
>   lcUsername = ""
>   lcPassword = ""
>ENDIF
>
>lcVerb = "GET"
>IF !EMPTY(lcPostBuffer)
>   lcVerb = "POST"
>   IF EMPTY(lcContentType)
>      IF (lcPostBuffer = "<?")
>         lcContentType = "text/xml"
>      ELSE
>         lcContentType = "application/x-www-form-urlencoded"
>      ENDIF
>   ENDIF
>ENDIF
>
>LOCAL loHttp as MSXML2.XMLHTTP
>loHttp = CREATEOBJECT("MSXML2.XMLHTTP")
>
>TRY
>   loHttp.Open(lcVerb,lcUrl,.f.,lcUsername,lcPassword)
>
>   IF !EMPTY(lcContentType)
>      loHttp.setRequestHeader("Content-type",lcContentType)
>   ENDIF
>
>   loHttp.Send(lcPostBuffer)
>
>   IF VERSION(5) > 800
>      lcResponse = CAST( loHTTP.responseBody as M )
>   ELSE
>      lcResponse = loHTTP.responseBody
>   ENDIF
>
>CATCH
>   AERROR(laErrors)
>   lcResponse =  "Error: " + laErrors[3]
>ENDTRY
>
>RETURN lcResponse
>
>
>Note that this will work only if the images linked are indeed HTTP links. If you have FTP links or local file links this code will break. More logic is needed to determine which protocol is used and based on that you could then grab the files with other protocols.
>
>
>+++ Rick ---
>
>
>
>>Greetings,
>>
>>I'm currently using the web browser control hosted in VFP to navigate pages and then using the DOM to extract source. That's all working well. Now I'm to the point where I have a list of images but I need to get these images and save them locally for offline browsing. What is the best way to get these into their appropriate files? I was trying to use the Internet Transfer control but can't seem to figure out how to actually create the appropriate file depending on gif, jpg, etc. Will the Internet transfer control maintain my session from the web browser? If not can I use the web browser control to somehow get the files?
>>
>>Any help is appreciated!
>>
>>Greg
Previous
Reply
Map
View

Click here to load this message in the networking platform