Page 1 of 2

Download online help with hmg

Posted: Sat Apr 30, 2016 4:40 am
by hmgchang
Dear Sirs,
I can save a web page from browser by ctrl S, but i have to click on the link to view the page and press ctrl S again...
I just need to code with hmg to downloaf / save by entering the web address. Any sample and help ?

Tia n best rgds
Chang...

Re: Download online help with hmg

Posted: Sat Apr 30, 2016 12:16 pm
by pctoledo
See this sample:

Code: Select all

#include "hmg.ch"

Function Main
Local cURL:="http://www.pctoledo.com.br/forum/"

	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 550 HEIGHT 163 ;
		TITLE 'HMG Demo' ;
		MAIN 

		@ 20,20 LABEL Label_1 ;
			WIDTH 80 ;
			HEIGHT 15 ;
			VALUE "Web Address"

		@ 38,20 TEXTBOX Text_1 ;
			WIDTH 500 ;
			HEIGHT 24 ;
			VALUE cURL ;
			TOOLTIP 'Web Address' ;
			MAXLENGTH 50 ;

		DEFINE BUTTON Button_1
			ROW	80
			COL	210
			WIDTH	100
			CAPTION	'Save URL'
			ACTION	{|| SaveURL()}
		END BUTTON

	END WINDOW

	Form_1.Center

	Form_1.Activate

Return Nil

*******************************
Function SaveURL()
LOCAL oHttp, cHtml, oDoc, c_Url:=alltrim(Form_1.Text_1.Value)

   oHttp := TIpClientHttp():new( c_Url )

   IF ! oHttp:open()
      MsgInfo("Connection error:", oHttp:lastErrorMessage())
      Return Nil
   ENDIF

   cHtml   := oHttp:readAll()
   oHttp:close()

   oDoc := THtmlDocument():new( cHtml )

   oDoc:writeFile( "Test.html" )

   MsgInfo("URL save file Test.html")

Return Nil

Re: Download online help with hmg

Posted: Sat Apr 30, 2016 10:40 pm
by hmgchang
Thank yiu Mr. Toledo...
I will try the code ...

Re: Download online help with hmg

Posted: Thu May 05, 2016 5:07 am
by hmgchang
Dear Mr. Toledo,

it works...
view online
view online
testhtml.PNG (65.26 KiB) Viewed 5348 times
but how to save a complete htm ?
view offline after saved
view offline after saved
realhtml.PNG (148.16 KiB) Viewed 5348 times

Re: Download online help with hmg

Posted: Thu May 05, 2016 5:32 pm
by pctoledo
Chang, this my demo copy only the page's HTML, but most sites have other auxiliary files (JavaScript, CSS, etc.) that were not copied.

In HTML the path to these files are shortened, if you edit the Test.html will notice the following:

Code: Select all

</script>
<script type="text/javascript" src="./styles/prosilver/template/styleswitcher.js"></script>
<script type="text/javascript" src="./styles/prosilver/template/forum_fn.js"></script>
<script type="text/javascript" src="./styles/prosilver/template/shCore.js"></script>
<script type="text/javascript" src="./styles/prosilver/template/shBrushClipper.js"></script>
<script type="text/javascript" src="./styles/prosilver/template/shBrushClipper2.js"></script>
  <link href="./styles/prosilver/theme/print.css" rel="stylesheet" type="text/css" media="print" title="printonly" />
  <link href="./style.php?sid=629b2353e4b2efd91408dbb6ac79c8e0&id=1&lang=en" rel="stylesheet" type="text/css" media="screen, projection" />
  <link href="./styles/prosilver/theme/shCore.css" rel="stylesheet" type="text/css" />
  <link href="./styles/prosilver/theme/shThemeMidnight.css" rel="stylesheet" type="text/css" />
  <link href="./styles/prosilver/theme/normal.css" rel="stylesheet" type="text/css" title="A" />
  <link href="./styles/prosilver/theme/medium.css" rel="alternate stylesheet" type="text/css" title="A+" />
  <link href="./styles/prosilver/theme/large.css" rel="alternate stylesheet" type="text/css" title="A++" />
<script type="text/javascript">
 SyntaxHighlighter.config.stripBrs = true;
 SyntaxHighlighter.config.clipboardSwf = "./styles/prosilver/theme/clipboard.swf";
 SyntaxHighlighter.all();
</script>
Note the codes src= or href= that starts with "./

If you replace all "./ by "http://www.pctoledo.com.br/forum/ the page is displayed correctly.

See the attached file.

Re: Download online help with hmg

Posted: Fri May 06, 2016 6:18 am
by serge_girard
Thanks Toledo !

Serge

Re: Download online help with hmg

Posted: Fri May 06, 2016 7:21 am
by mol
You can create syntax analyzer, which will read html as xml, test some phrases as script, css to download these files too.
It shouldn't be very hard to code :)

Re: Download online help with hmg

Posted: Sun May 15, 2016 2:06 pm
by hmgchang
Thks Toledo... i can learn alot...
Thks Mol for the idea but i am dont understand about the analyzer nor the xml... but you gave me something to dig ... pls be kind to guide me...

TIA
Best rgds
Chang

Re: Download online help with hmg

Posted: Sun May 15, 2016 2:41 pm
by mol
I'll try to produce little sample tomorrow

Re: Download online help with hmg

Posted: Mon May 16, 2016 8:38 am
by mol
Hi!
Try this sample

Code: Select all

/*
 2016.05.16 Marek Olszewski MOL 
Read WWW sample
*/


#include <hmg.ch>

Function Main

	Public cWWWFile := "test.html"
	
	DEFINE WINDOW Main ;
        AT 0,0 ;
        WIDTH 600 HEIGHT 600 ;
        TITLE 'Read WWW sample' ;
		Main  
		
	
		DEFINE BUTTON B1
			ROW    20
			COL    20
			WIDTH  200
			HEIGHT 30
			Caption "Click to read www document"
			FONTNAME "Arial"
			FONTSIZE 9
			ACTION ImportWWW(cWWWFile)
		END BUTTON

		DEFINE GRID Grid_Links
			ROW 70
			COL 40
			WIDTH 500 
			HEIGHT 480
			HEADERS {'Files to download'} 
			WIDTHS {480} 
			ITEMS {}
		END GRID

	END WINDOW
	
	Center Window Main
	Activate Window Main

Return
*------------------------
function ImportWWW
	local cWWWFile
	
	local aFilesToDownload := {}
	
	cWWWFile := Getfile ( { {'HTML','*.html'},{'HTM','*.htm'} },'Select html file' , '.', .f. , .t. )
	
	if hb_FileExists( cWWWFile)
		cWWW := memoread(cWWWFile )
	else
		return .f.
	endif
	
	if cWWW  == NIL
		msgstop("Something wrong with "+cWWWFile + " file")
		return .f.
	endif
	
	TokenInit(@cWWW,"<>")

	do while .not. TokenEnd()
		cLink := ''
		cTag := alltrim(TokenNext(cWWW))

		if hmg_lower(cTag) = "link"
			cLink := StripTag(cTag,"href")
		
		elseif hmg_lower(cTag) = "script"
			cLink := StripTag(cTag,"src")
		
		elseif hmg_lower(cTag) = "img"
			cLink := StripTag(cTag,"src")
		
		endif
		
		if !empty(cLink)
			aAdd(aFilesToDownload, cLink)
			Main.Grid_Links.AddItem({cLink})
		endif
	enddo
	
	//msgdebug(aFilesToDownload)
return .t.
	
*-------------------
function StripTag
	param cTag, cKeyword
	local i
	local cLink
	
	i := hb_at(cKeyword, hmg_lower(cTag))
	if i > 0
		// cut path and filename
		cTag := substr(cTag,i)
		i := hb_at('"', cTag)
		cTag := substr(cTag,i+1)
		i := hb_at('"', cTag)
		cLink := left(cTag,i-1)
	endif
return cLink
*----------------------