* Review the method "GetHtmlContents()" in the class definition "MyForm".
* For the IE object model see:
* [URL unfurl="true"]http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/reference/objects/internetexplorer.asp[/URL]
local oForm
oForm = createobject("MyForm")
oForm.show()
read events
define class MyForm as form
docreate = .t.
autocenter = .t.
datasession = 2
width = 800
height = 500
caption = "View HTML page's source"
cURL = ""
cHTMLSource = ""
add object lblURL as label with ;
top = 5, ;
left = 5, ;
caption = "Enter a valid URL", ;
autosize = .t.
add object txtURL as textbox with ;
left = 5, ;
top = this.lblURL.top + this.lblURL.height , ;
width = 500, ;
height = 24, ;
fontname = "courier new", ;
controlsource = "thisform.cURL"
add object cmdGetHTML as commandbutton with ;
top = this.txtURL.top, ;
width = 100, ;
height = 24, ;
left = this.txtURL.left + this.txtURL.width + 4, ;
caption = "Get HTML"
add object lblHTML as label with ;
left = 5, ;
top = this.txtURL.top + this.txtURL.height + 5, ;
caption = "Retrieved HTML Source", ;
autosize = .t.
add object edtHTML as editbox with ;
left = 5, ;
top = this.lblHTML.top + this.lblHTML.height, ;
width = this.width - 10, ;
height = this.height - this.lblHtml.top + this.lblHTML.height - 40, ;
fontname = "courier new", ;
controlsource = "thisform.cHTMLSource"
procedure load
set cent on
set safe off
set escape on
endproc
procedure destroy
clear events
endproc
procedure cmdGetHTML.click
thisform.GetHTMLContents()
endproc
procedure GetHtmlContents
this.cHTMLSource = ""
this.refresh()
local oIE, cDocContents, oWaitForm
oWaitForm = createobject("frmWait")
oWaitForm.SetMessage("Please Wait...")
oWaitForm.show()
oIE = createobject('internetexplorer.application')
oIE.Navigate(this.cURL)
* Wait until IE navigates to the site
do while oIE.busy
enddo
* Wait until IE finishes parsing the document
do while oIE.document.readystate <> "complete"
* (On some sites it makes a difference and
* the document will not be parsed yet even
* though the busy flag of IE is true)
enddo
* Get the document contents
cDocContents = ""
if oIe.document.all(0).tagname == "!"
* If the first element is a DTD
cDocContents = oIe.document.all(0).text + chr(13)+chr(10)
* The second element will be of type "html"
cDocContents = cDocContents + oIe.document.all(1).outerhtml
else
* The first element is of type "html"
cDocContents = oIe.document.all(0).outerhtml
endif
oIE.quit
this.cHTMLSource = cDocContents
this.refresh()
oWaitForm.release()
this.edtHTML.setfocus()
endproc
enddefine
* Wait window
define class frmWait as form
docreate = .t.
autocenter = .t.
borderstyle = 0
titlebar = 0
width = 200
height = 50
alwaysontop = .t.
cMessage = ""
add object txtMessage as textbox with ;
top = 2,;
left = 2, ;
alignment = 2, ;
width = this.width -4, ;
height = this.height - 4, ;
forecolor = rgb(255,255,255), ;
backcolor = rgb(0,0,0), ;
fontsize = 14, ;
controlsource = "thisform.cMessage"
procedure SetMessage
lparam cMessage
this.cMessage = cMessage
this.refresh()
endproc
enddefine