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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save with webbrowser control?

Status
Not open for further replies.

dal98

Technical User
Nov 17, 2001
9
US
Hi, I want to save the HTML of a webpage and have tried to do so using a webbrowser control. I have successfully used the .Navigate method, but I don't know any way to save the file to disk. Is this possible?

.Visible is set to false as I do not want to display the page, I'm thinking this is creating more overhead than should be needed. Is there a faster or more efficient way to do this?

Thanks,
Derek
 
Hi

LOCAL lcArticle, lcAddress
** the text and the webpages address respectively.

_clipText = ""
ThisForm.Obrowser.Document.ExecCommand("COPY")
lcArticle = _clipText
IF EMPTY(lcArticle)
ThisForm.Obrowser.Document.ExecCommand("SelectAll")
ThisForm.Obrowser.Document.ExecCommand("Copy")
ENDIF
lcArticle = _clipText
ThisForm.Obrowser.Document.ExecCommand("UnSelect")
lcAddress = ThisForm.oBrowser.LocationUrl

:)


____________________________________________
ramani - (Subramanian.G) :)
When you ask VFP questions, please add VFP version.
 
Baltman wrote a nice FAQ that reads the tek-tip page and parses out all the tips into a nice table/form. Take a look at his tek-tip. What it is doing is reading the webpage and then parsing out the data he needs. You could modify it to fit your needs and then just write the lines to an HTML document.

How can I navigate through all these FAQs? faq184-4339

I believe this is piece of his code that is a good starting point. Then look at how he puts the data into an array using alines()

IF VarConnect="Y"
WAIT WINDOW AT SROWS()/2, SCOLS()/2 "Getting FAQ listing from Tek-Tips" nowait
lcURL=" objHTTP = CreateObject("MSXML2.XMLHTTP")
objHTTP.Open("GET", lcURL, .f.)
objHTTP.Send
FAQs=(objHTTP.ResponseText)
IF DIRECTORY('c:/temp')=.f.
MKDIR c:/temp
ENDIF
STRTOFILE(FAQs,"c:/temp/Offline.txt")
ENDIF





Jim Osieczonek
Delta Business Group, LLC
 
Hi Derek,

You need to call the browser's ExecWB() method. Essentially, that executes any command from the browser's menu. You pass it a parameter to tell it which command to execute. Trouble is, I don't know what parameter to pass for "Save As" -- maybe 5. But you can always experiment.

Mike


Mike Lewis
Edinburgh, Scotland
 
Good suggestion MikeLewis. I helped with these constants for a FAQ that Gagnon wrote, a complete list of ExecWB() constants can be found in:

How to use the Internet Explorer's preview to view a report
faq184-3503

Slighthaze = NULL
[sub]craig1442@mchsi.com[/sub][sup]
"Whom computers would destroy, they must first drive mad." - Anon​
[/sup]
 
Slighthaze,

So, according to that FAQ, my guess was right - 5 for the first parameter. He might also need a second parameter - maybe 0 or 1 depending on whether he wants the user to see a prompt.

Mike


Mike Lewis
Edinburgh, Scotland
 
Hi

This FAQ may be useful.

A way to collect your KB articles from internet.
FAQ184-4463

:)

____________________________________________
ramani - (Subramanian.G) :)
When you ask VFP questions, please add VFP version.
 
Dal98

Here is another way to download the contents of a webpage.
Code:
Create Cursor myCursor (contents m)
Public oForm
oForm = Createobject("form")
oForm.AddObject("edit1","editbox")
oForm.edit1.Visible=.T.
oForm.Height = 400
oForm.Width = 400
oForm.edit1.Width=390
oForm.edit1.Height=390
oForm.AutoCenter=.T.
oForm.edit1.ControlSource = "mycursor.contents"

SELECT myCursor
Append Blank
Replace contents With FETCHURL( "[URL unfurl="true"]http://www.microsoft.com"[/URL] )
oForm.Show(1)
Function FETCHURL
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
lsAgent = "VPF"

lhInternetSession = InternetOpen( lsAgent, INTERNET_OPEN_TYPE_PRECONFIG, ;
	'', '', SYNCHRONOUS)
If lhInternetSession = 0
	Wait Window "Internet session cannot be established" Time 2
	Return .Null.
Endif
lhUrlFile = InternetOpenUrl( lhInternetSession, pcUrlName, '', 0, ;
	INTERNET_FLAG_RELOAD, 0)
If lhUrlFile = 0
	Wait Window "URL cannot be opened"
	Return .Null.
Endif
lcRetVal = ""
llOk = .T.
Do While llOk
	lsReadBuffer = Space(32767)
	lnBytesRead = 0
	lnOk = InternetReadFile( lhUrlFile, @lsReadBuffer, Len(lsReadBuffer), @lnBytesRead)
	If ( lnBytesRead > 0 )
		lcRetVal = lcRetVal + Left( lsReadBuffer, lnBytesRead )
	Endif
	llOk = ( lnOk = 1 ) And ( lnBytesRead > 0 )
Enddo
InternetCloseHandle( lhUrlFile )
InternetCloseHandle( lhInternetSession )
Return lcRetVal
Endfunc

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
A very fast way:

************************************************************
* Parameter: Name of URL which points to a file to download.
* Parameter: Local file to which to download.
* Return : .T./.F.
************************************************************
FUNCTION lURLGetFile( tcURL, tcLocalName )
************************************************************
m.tcURL = ALLTRIM( m.tcURL )
m.tcLocalName = ALLTRIM( m.tcLocalName )

* In C:\Winnt\System32\urlmon.dll.
DECLARE INTEGER URLDownloadToFile IN urlmon.dll;
INTEGER pCaller, STRING szURL, STRING szFileName, ;
INTEGER dwReserved, INTEGER lpfnCB

* Returns 0 if succeeeds, a large negative number if fails.
IF URLDownloadToFile( 0, m.tcURL, m.tcLocalName, 0, 0 ) = 0
RETURN .T.
ELSE
RETURN .F.
ENDIF


Andy Rice
San Diego, CA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top