[futurebasic] Re: [FB] View Source from FB

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : August 2004 : Group Archive : Group : All Groups

From: Bernie Wylde <bernie.w@...>
Date: Sat, 7 Aug 2004 07:54:24 +0100
On 6 Aug 2004, at 23:37, tedd wrote:

>>  HTMLRenderingLibrary - Display HTML documents in your application.
> Neat.
> From FB, does anyone have a way to get (i.e., download) the text 
> content from a specific url?
> In other words, does anyone have a way from FB (given the url) to 
> download all the text found at that specific address (i.e., html, 
> embedded scripts, text, links, whatever)? It would be equivalent to 
> doing a "View Source" from a browser.
> TIA for any help.

Tedd,

In this quick'n'dirty demo, I've ripped the bit that does the business 
from Alain's CodeStyler.

:-bernie


'~'A
'                       Runtime : Rntm Appearance.Incl
'                           CPU : Carbon
'                    CALL Req'd : Off
'~'B
include "Tlbx URLAccess.Incl"

_wViewURLSourceDemo = 1
begin enum 1
_cURLStat
_cURLFld
_cViewBtn
_cSourceFld
end enum

local fn BuildwViewURLSourceDemo
dim as Str255              s
dim as ControlFontStyleRec cfs
dim as WindowAttributes    wa
dim as Rect                r
'~'1
cfs.flags = _kControlUseFontMask_kControlUseJustMask
cfs.font = _kControlFontSmallSystemFont
cfs.just = _teJustLeft

SetRect(r, 9, 52, 631, 558)
appearance window -_wViewURLSourceDemo,¬
                   "View URL Source Demo", @r,¬
                   _kDocumentWindowClass
'~'1
SetRect(r, 20, 23, 49, 36)
appearance button _cURLStat,¬
                   _activeBtn,,,,, @r,¬
                   _kControlStaticTextProc
def SetButtonFontStyle(_cURLStat, cfs)
def SetButtonTextString(_cURLStat, "URL:")

SetRect(r, 53, 23, 541, 36)
appearance button _cURLFld,¬
                   _activeBtn,,,,, @r,¬
                   _kControlEditTextProc
def SetButtonFontStyle(_cURLFld, cfs)
s = "http://homepage.ntlworld.com/bernie.w/twm148.htm"
def SetButtonTextString(_cURLFld, s)

SetRect(r, 23, 60, 599, 483)
text _kThemeSystemFont, 11
edit field _cSourceFld, "", @r, _statFramed
SetRect(r, 599, 59, 614, 484)
scroll button -_cSourceFld,0,0,0,0, @r, _scrollOther

SetRect(r, 552, 20, 602, 37)
appearance button _cViewBtn, _activeBtn,,,,¬
                   "View", @r, _kControlPushButtonProc
def SetButtonFontStyle(_cViewBtn, cfs)

appearance window _wViewURLSourceDemo
end fn

local fn cView
dim as Str255   URL
dim as Str15    oldSubStr, newSubStr
dim as Handle   srcH
dim as long     found
dim as short  @ size
dim as OSStatus err
dim as short    try
'~'1
srcH = fn NewHandle(0)
long if srcH
URL = fn ButtonTextString$(_cURLFld)
fn FBPStr2CStr(URL)
try = 3
do
err = fn URLSimpleDownload(URL, #_nil, srcH, _nil, _nil, #_nil)
try--
until try == 0 or err == _noErr
if err then exit "abort"

size = fn GetHandleSize(srcH)
SetHandleSize(srcH, size + 2)
BlockMove [srcH], [srcH] + 2, size
% [srcH], size

oldSubStr = chr$(10)
newSubStr = chr$(13)
do
found = fn munger(srcH, 2, @oldSubStr[1], oldSubStr[0],¬
                            @newSubStr[1], newSubStr[0])
until found < 0

edit field _cSourceFld, &srcH

DisposeHandle(srcH) : srcH = _nil
exit fn
"abort"
if srcH then DisposeHandle(srcH)
end if
end fn

local fn Init
gFBEditSelectAll = _zTrue
edit menu 2
fn BuildwViewURLSourceDemo
end fn

local fn DoDialog
dim as long ev, id
'~'1
ev = dialog(0)
id = dialog(ev)
select ev
case _btnClick
select window(_outputWnd)
case _wViewURLSourceDemo
select id
case _cViewBtn : fn cView
end select
end select
end select
end fn

fn Init

on dialog fn DoDialog

do
HandleEvents
until gFBQuit