Download online help with hmg
Moderator: Rathinagiri
Download online help with hmg
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...
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 !
Re: Download online help with hmg
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
Dear Mr. Toledo,
it works... but how to save a complete htm ?
it works... but how to save a complete htm ?
Just Hmg It !
Re: Download online help with hmg
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:
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.
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>
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
- 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
Thanks Toledo !
Serge
Serge
There's nothing you can do that can't be done...
Re: Download online help with hmg
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
It shouldn't be very hard to code
Re: Download online help with hmg
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
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 !
Re: Download online help with hmg
I'll try to produce little sample tomorrow
Re: Download online help with hmg
Hi!
Try this sample
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
*----------------------