Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving an HTML document from the web

Status
Not open for further replies.

dddenney

Programmer
Nov 29, 2000
41
US
Does any know how to use the "Save As" feature in Internet Explorer when using either the Internet Explorer object or the Web Browser control. Are there any other tools that can download a web page from the internet?

Thanks in advance,

Dan
 
Here is how to get the content of a webpage:
create cursor xtemp mtemp (m)
append blank
replace mtemp with ReadURL( " )
copy memo mtemp to somejpg.jpg

The modified code follows:

* readurl.prg 06-Mar-98

* 06-Mar-98 pulled from Q174524 on March 98 Technet CD
* 06-Mar-98 bug fixed about the length of the sReadBuffer

*Any Internet or intranet URL can be passed as a parameter. Microsoft.com
*was chosen for this example.

*Note that Microsoft Internet Explorer must be installed on the computer.

* passed: URLName, in the form "*
* returns: the content of the URL
*
* usage:
*
* uWebContent = ReadURL( " )
* uWebContent = ReadURL( " )
*
* notes:
* 1 - IE does not need to be running to use this, but must be installed,
* as the program uses an option that gets information from the registry
Code:
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"
   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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top