Download online help with hmg

HMG en Español

Moderator: Rathinagiri

User avatar
hmgchang
Posts: 273
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia

Download online help with hmg

Post 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...
Just Hmg It !
User avatar
pctoledo
Posts: 123
Joined: Wed Aug 25, 2010 10:45 am
Location: Araçatuba - SP - Brazil
Contact:

Re: Download online help with hmg

Post 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
Regards/Saludos,

Toledo

Clipper On Line
User avatar
hmgchang
Posts: 273
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia

Re: Download online help with hmg

Post by hmgchang »

Thank yiu Mr. Toledo...
I will try the code ...
Just Hmg It !
User avatar
hmgchang
Posts: 273
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia

Re: Download online help with hmg

Post by hmgchang »

Dear Mr. Toledo,

it works...
view online
view online
testhtml.PNG (65.26 KiB) Viewed 5240 times
but how to save a complete htm ?
view offline after saved
view offline after saved
realhtml.PNG (148.16 KiB) Viewed 5240 times
Just Hmg It !
User avatar
pctoledo
Posts: 123
Joined: Wed Aug 25, 2010 10:45 am
Location: Araçatuba - SP - Brazil
Contact:

Re: Download online help with hmg

Post 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.
Attachments
Test2.zip
(8.65 KiB) Downloaded 219 times
Regards/Saludos,

Toledo

Clipper On Line
User avatar
serge_girard
Posts: 3166
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Download online help with hmg

Post by serge_girard »

Thanks Toledo !

Serge
There's nothing you can do that can't be done...
User avatar
mol
Posts: 3721
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Download online help with hmg

Post 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 :)
User avatar
hmgchang
Posts: 273
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia

Re: Download online help with hmg

Post 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
Just Hmg It !
User avatar
mol
Posts: 3721
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Download online help with hmg

Post by mol »

I'll try to produce little sample tomorrow
User avatar
mol
Posts: 3721
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Download online help with hmg

Post 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
*----------------------
Post Reply