Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to get a jpg from a website
Message
From
29/08/2011 09:50:15
 
 
To
29/08/2011 08:24:10
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows 2008 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01521872
Message ID:
01522080
Views:
65
getElementById and getElementsByTagName are some of the methods which are exposed by Internet Explorer.

>This code is very interesting. I did not know the methods 'getElementById' and 'getElementsByTagName'. They are very useful.
>I already have a solution that finds the correct image in the cache.
>
>Thank you very much,
>
>Lennert
>
>>>Thank you for your quick reply, bu sorry, it is not as 'easy' as that.
>>>
>>>I want to download a captcha from google and present it in a vfp-form, but the captcha is not so easily isolated by automation. Interactively I can just right-click and can save the image, but I don't know how to do that automatically.
>>>Google-captcha's do not have normal URLs.
>>
>>The captcha will be an image element on the page and you can select it in the DOM. If it has an ID you can do:
>>
>>
>>loImg = oBrowser.document.getElementById("imgCatpcha")
>>lcUrl = loImg.src
>>
>>*** Retrieve the image and store to disk
>>Do wwHttp
>>loHttp = CREATEBOBJECT("wwHttp")
>>
>>*** Save output directly to file
>>loHttp.HttpGet(lcUrl,"","","c:\temp\captchaimage.jpg")
>>
>>
>>Then you can use the code Tore posted or some other mechanism like the wwHttp code I use above to retrieve the data using HTTP.
>>
>>If there's no ID on the image then you can select all images and loop through them to find what you're looking for by looking at the .src property:
>>
>>
>>loImgs = loDoc.getElementsByTagName("img")
>>FOR EACH loImg IN loImgs
>>   ? loImg.Src
>>ENDFOR
>>
>>
>>+++ Rick ---
>>
>>
>>
>>>
>>>>If you know the URL, you can use GetDataFromURL
>>>>Strtofile(GetDataFromURL('yourURL','yourfilename.jpg')
>>>>
>>>>Function GetDataFromURL
>>>>LPARAMETERS pcUrlName
>>>>DECLARE INTEGER InternetOpen IN wininet.DLL STRING sAgent, ;
>>>>      INTEGER lAccessType, STRING sProxyName, ;
>>>>      STRING sProxyBypass, INTEGER lFlags
>>>>
>>>>DECLARE INTEGER InternetOpenUrl IN wininet.DLL ;
>>>>   INTEGER hInternetSession, STRING sUrl, STRING sHeaders,;
>>>>   INTEGER lHeadersLength, INTEGER lFlags, INTEGER lContext
>>>>
>>>>DECLARE INTEGER InternetReadFile IN wininet.DLL INTEGER hfile, ;
>>>>      STRING @sBuffer, INTEGER lNumberofBytesToRead, INTEGER @lBytesRead
>>>>
>>>>DECLARE short InternetCloseHandle IN wininet.DLL INTEGER hInst
>>>>
>>>>#DEFINE INTERNET_OPEN_TYPE_PRECONFIG 0
>>>>#DEFINE INTERNET_OPEN_TYPE_DIRECT 1
>>>>#DEFINE INTERNET_OPEN_TYPE_PROXY 3
>>>>#DEFINE SYNCHRONOUS 0
>>>>#DEFINE INTERNET_FLAG_RELOAD 2147483648
>>>>#DEFINE CR CHR(13)
>>>>
>>>>local lsAgent, lhInternetSession, lhUrlFile, llOk, lnOk, lcRetVal, lcReadBuffer, lnBytesRead
>>>>
>>>>* what application is using Internet services?
>>>>lsAgent = "VPF 5.0"
>>>>
>>>>lhInternetSession = InternetOpen( lsAgent, INTERNET_OPEN_TYPE_PRECONFIG, ;
>>>>      '', '', SYNCHRONOUS)
>>>>
>>>>* debugging line - uncomment to see session handle
>>>>* WAIT WINDOW "Internet session handle: " + LTRIM(STR(hInternetSession))
>>>>
>>>>IF lhInternetSession = 0
>>>>   WAIT WINDOW "Internet session cannot be established" TIME 2
>>>>   RETURN .null.
>>>>ENDIF
>>>>
>>>>lhUrlFile = InternetOpenUrl( lhInternetSession, pcUrlName, '', 0, ;
>>>>                             INTERNET_FLAG_RELOAD, 0)
>>>>
>>>>* debugging line - uncomment to see URL handle
>>>>* WAIT WINDOW "URL Handle: " + LTRIM(STR(hUrlFile))
>>>>
>>>>IF lhUrlFile = 0
>>>>   WAIT WINDOW "URL cannot be opened" Timeout 5
>>>>   RETURN .null.
>>>>ENDIF
>>>>
>>>>lcRetVal = ""
>>>>llOk = .t.
>>>>
>>>>DO WHILE llOK
>>>>   * set aside a big buffer
>>>>   lsReadBuffer = SPACE(32767)
>>>>   lnBytesRead = 0
>>>>   lnOK = InternetReadFile( lhUrlFile, @lsReadBuffer, LEN(lsReadBuffer), @lnBytesRead)
>>>>
>>>>   if ( lnBytesRead > 0 )
>>>>      lcRetVal = lcRetVal + left( lsReadBuffer, lnBytesRead )
>>>>   endif
>>>>
>>>>   * error trap - either a read failure or read past eof()
>>>>   llOk = ( lnOK = 1 ) and ( lnBytesRead > 0 )
>>>>ENDDO
>>>>
>>>>* close all the handles we opened
>>>>InternetCloseHandle( lhUrlFile )
>>>>InternetCloseHandle( lhInternetSession )
>>>>
>>>>* return the URL contents
>>>>RETURN lcRetVal
>>>>
>>>>
>>>>>Hello everybody
>>>>>
>>>>>I automate IE9, by:
>>>>>
>>>>>
>>>>>goIE = CREATEOBJECT("InternetExplorer.Application")
>>>>>
>>>>>
>>>>>and by goIE.navigate() I navigate to a URL. There is a jpg-image there, which I want to get on my local disk. I do not have the slightest idea...
>>>>>Any help appreciated!
>>>>>
>>>>>TIA
>>>>>
>>>>>Lennert
Previous
Reply
Map
View

Click here to load this message in the networking platform