WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Examples

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Design Your Own Web Browser

Keywords:  URLGetScheme	 HTTPGetServer	HTTPGetPath  HTTPGetDir	 HTTPStripHTML

;**************************************************************************
;		 WEB CLIENT SAMPLE WINSOCK APP
;
; Usage: Run this file from WinBatch, optionally with 2 params:
;	 Web.WBT "<your dialup name>" "<your ISP>"
;
; Author: Jennifer Palonus (GDI)
; 
;  Date	   Major changes
; -------  ----------------------------------------------------------------
; 13mar96  Created as ClockMan95 WIL script.
; 22mar96  Builds a list of all http links in the HTML page.
; 30apr96  Standalone WBT script (with WXSock WIL extender).
;**************************************************************************
sTitle = "Move Over Netscape!"


AddExtender ("wwwsk34I.dll")


;Dial our host, asking first if user has more than 1 defined...
hConn = 0
sDialUps = DUNItemize ()
if (ItemCount(sDialUps,@TAB) == 1)
	sDial = sDialUps
else
	sDial = AskItemList ("Choose a dial-up connection", sDialUps, @TAB, @SORTED, @SINGLE)
endif

hConn = DUNConnect (sDial)
nErr = wxGetLastErr()
if (!hConn)
	select (nErr)
		case @SErrBusy
			Message (sTitle, "Couldn't connect to %sDial%: Line busy.")
			break
		case @SErrNoAnswer
			Message (sTitle, "Couldn't connect to %sDial%: No answer.")
			break
		case @SErrVoice
			Message (sTitle, "Couldn't connect to %sDial%: A human answered.")
			break
		case nErr
			Message (sTitle, "Couldn't connect to %sDial%: Error %nErr%.")
	end select
	exit
endif


; This is our "browser"...
if (!WinExist (sTitle))
	Run ("notepad.exe","%sTitle%.")
	if (WinExistChild("Notepad", "Cannot find the %sTitle%"))
		SendKeysChild ("Notepad", "Cannot find the %sTitle%", "~")
	endif
	WinTitle ("%sTitle% - Notepad", sTitle)
	SendKeysTo (sTitle, "!ew") ; Turn on word-wrap
else
	; Clear the existing browser window...
	SendKeysTo (sTitle, "!ea{del}")
endif


; Main command loop...
sURL = "http://"
sURLScheme = "http"
sURLServer = ""
sURLPath = "/"
sURLDir = "/"
sURLList = ""
sCmd = "<other>"

while (sURL<>"")
	; Get the URL...
	if (sURLList <> "")
		sURLList = ItemInsert ("<other>", -1, sURLList, @TAB) 
		sCmd = AskItemList ("Choose the URL, <other>, or Cancel to exit:", sURLList, @TAB, @Unsorted, @Single)
		if (sCmd=="")
			break ; Break out of the main loop & fall thru to hang up
		endif
	endif

	if (sURLList=="" || sCmd=="<other>")
		sURL = AskLine (sTitle, "Enter the URL:", sURL)
	else
		sURL = sCmd
	endif

	sURLScheme = URLGetScheme (sURL, "http")
	if (sURLScheme <> "http")
		Message (sTitle, "%sTitle% doesn't handle %sURLScheme%.")
		sURLList = ""
		continue
	endif

	sURLServer = HTTPGetServer (sURL, sURLServer)
	sURLPath   = HTTPGetPath   (sURL, sURLDir)
	sURLDir	   = HTTPGetDir	   (sURL, sURLDir)
	if (sURLServer == "")
		Message (sTitle, "No server specified.")
		sURLList = ""
		continue
	endif

	; Clear our browser window...
	SendKeysTo (sTitle, "!ea{del}")

	; Get the Web page...
	sPage = HTTPRecvText (sURLServer, sURLPath, 32767, @TRUE)
	nErr = wxGetLastErr()
	if (nErr <> @SOK)
		Message (sTitle, "Error receiving web page: %nErr%")
		continue
	endif

	; Display the HTML page in our browser window...
	sPlainPage = HTTPStripHTML (sPage)
	ClipPut (sPlainPage)
	SendKeysTo (sTitle, "^v~")
	Drop (sPlainPage)

	; Extract the links from this page...
	gosub ParsePage
endwhile

; User hit Cancel...
:Cancel

; Hang up...
:HangUp
if (hConn)
	nRet = DUNDisconnect (hConn)
endif

; Close our browser window...
SendKeysTo (sTitle, "!fx")

exit


;**************************************************************************
; Extract all the hyperlinks from sPage into sURLList.
;**************************************************************************
:ParsePage
sURLList = ""
if (StrLen(sPage) < 5)
	return
endif

; Convert to lower case
spage = strlower(spage)


nPPH  = 1 ; Pos of "HREF="
nPPQ1 = 1 ; Pos of 1st quote of a link URL
nPPQ2 = 1 ; Pos of 2nd quote of a link URL
while (nPPH > 0)
	nPPH = StrIndex (sPage, "href=", nPPQ2, @FWDSCAN)
	if (nPPH > 0)
		nPPQ1 = StrIndex (sPage, '"', nPPH+5,  @FWDSCAN)
		if (nPPQ1 > 0)
			nPPQ2 = StrIndex (sPage, '"', nPPQ1+1, @FWDSCAN)
			if (nPPQ2 > 0)
				sPPURL = StrSub (sPage, nPPQ1+1, nPPQ2-nPPQ1-1)
				sURLList = ItemInsert (sPPURL, -1, sURLList, @TAB)
			endif
		endif
	endif
endwhile

return


Article ID:   W12632
Filename:   Design Your Own Web Browser.txt
File Created: 2001:03:01:15:10:40
Last Updated: 2001:03:01:15:10:40