Jump to content

Recommended Posts

Posted (edited)

I'm trying to save opened page in one MHT page.

I found many solutions like this:

_INetGetMHT( "http://www.yahoo.com", "C:\test.MHT" )
Func _INetGetMHT( $url, $file )
    Local $msg = ObjCreate("CDO.Message")
    If @error Then Return False
    Local $ado = ObjCreate("ADODB.Stream")
    If @error Then Return False

    With $ado
        .Type = 2
        .Charset = "US-ASCII"
        .Open
    EndWith
    $msg.CreateMHTMLBody($url, 0)
    $msg.DataSource.SaveToObject($ado, "_Stream")
    FileDelete($file)
    $ado.SaveToFile($file, 1)
    $msg = ""
    $ado = ""
    Return True
EndFunc

 

but can't find any which show how to save WebPage using AutoIt opened by _IE.. Functions. 

but I come to this page:

http://microsoft.public.scripting.vbscript.narkive.com/WqvoHF8S/retrieve-html-from-a-website-using-vbscript#post3

 

<!-- FileName : SaveMhtmEn.hta -->
<html><head><script language=vbs>
Dim EvtSrc, WS, FS, URL, Path, Title, EN

Set WS = CreateObject("WScript.Shell")
Set FS = CreateObject("Scripting.FileSystemObject")

On Error Resume Next
Set EvtSrc=external.menuarguments.event.srcelement
EN = Err.Number
On Error GoTo 0
If EN <> 0 Then Reg_UnReg
'
Sub SaveAsMhtml()
URL = EvtSrc.Href
If IsNull(URL) Or LCase(Left(URL, 7)) <> "http://" Then _
ShowMessage 1
Path = "%userprofile%\My Documents\HomePages\"
Path = WS.ExpandEnvironmentStrings(Path)
If Not FS.FolderExists(Path) Then FS.CreateFolder Path
external.menuarguments.status = "Now downloading..."

With CreateObject("InternetExplorer.Application")
.Navigate URL
Do While .Busy: Loop
Title = .Document.Title:If Title = "" Then Title = ":"

With CreateObject("CDO.Message")
On Error Resume Next
.CreateMHTMLBody(URL)
If Err Then On Error GoTo 0: ShowMessage 2
FS.CreateTextFile Path & Title & ".mht"
If Err Then _
Title = Replace(Date, "/", "_") & "_" & Replace(Time, ":", "_")
On Error GoTo 0
.BodyPart.GetStream.SaveToFile Path & Title & ".mht", 2
End With

.Quit
End With

external.menuarguments.status = ""
ShowMessage 3
End Sub
'
Sub ShowMessage(Mes)
Select Case Mes
Case 1: WS.PopUp "No link address.", 2
Case 2: WS.PopUp "Downloading failed", 2
Case 3: WS.PopUp "Downloading finished.", 2
End Select
window.close
End Sub
'
Sub Reg_UnReg()
Const RootKey = "HKCU\Software\Microsoft\Internet Explorer\MenuExt\"
Const Name = "SaveAs &Mht Format"
Dim Path, TKey, Dummy, EN
Path = document.urlunencoded
TKey = RootKey & Name & "\"
On Error Resume Next
Dummy = WS.RegRead(TKey): EN = Err.Number
On Error GoTo 0
If EN = 0 Then
WS.RegDelete TKey
WS.PopUp "Deleted from context menu", 2
Else
WS.RegWrite TKey, Path, "REG_SZ"
WS.RegWrite TKey & "contexts", &H20, "REG_DWORD"
WS.PopUp "Added to context menu", 2
End If
window.close
End Sub
</script></head><body onload=SaveAsMhtml></body></html>

 

Question:

How to use this code in page opened by AutoIt  _IE... functions ?

 

Best regards,

mLipok

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

I'm a little confused (as usual).

Are you using a local HTML page or a URL?

Are you trying to save that page as a MHT page or extracting something from a MHT page and trying to save as HTML?

 

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

  Reveal hidden contents

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Posted
  On 5/8/2015 at 12:09 PM, Danp2 said:

I believe that he wants to save the currently opened IE page into an MHT.

Exactly 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

and here is a solution:

http://www.codeproject.com/Articles/2847/Automated-IE-SaveAs-MHTML

But my c++ knowledge is very poor.

So I have a question can somebody translate this cod to AutoIt ?

 

Best regards,

mLipok

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • 5 months later...
Posted (edited)

some small progress ;)

#include <MsgBoxConstants.au3>
#include <ie.au3>
_IEErrorHandlerRegister(_My_ErrFunc)

;~ https://msdn.microsoft.com/en-us/library/hh772065(v=vs.85).aspx
;~ https://msdn.microsoft.com/en-us/library/ms535231(v=vs.85).aspx

Example()

Func Example()
     ;; Local $oIE = _IECreate('http://samples.msdn.microsoft.com/workshop/samples/css/cssText/cssText.html',1)
     
     ; this following site is better for example
     Local $oIE = _IECreate('http://www.w3schools.com/css/default.asp',1)

    _IE_SaveToFile($oIE,@ScriptDir & '\Save_Example_NoCSS.html', False)
    ShellExecute(@ScriptDir & '\Save_Example_NoCSS.html')
    _IE_SaveToFile($oIE,@ScriptDir & '\Save_Example_WithCSS.html', True)
    ShellExecute(@ScriptDir & '\Save_Example_WithCSS.html')

EndFunc   ;==>Example

Func _IE_CSSGetAll(ByRef $oIE)
    Local $oStyle_coll = $oIE.document.styleSheets
    If @error Then MsgBox($MB_ICONERROR, '$oIE.document.styleSheets', _
            '@error = ' & @error & @CRLF & '@extended = ' & @extended)

    Local $sCSS_Styles = ''
    For $oStyle_enum In $oStyle_coll
        $sCSS_Styles &= $oStyle_enum.cssText & @CRLF
    Next
    Return SetError(0, 0, $sCSS_Styles)

EndFunc   ;==>_IE_CSSGetAll

Func _IE_SaveToFile($oIE, $sHTML_FileFullPath, $bSaveCSS = False)

    If $bSaveCSS Then
        Local $sCSS_Styles = _IE_CSSGetAll($oIE)

        Local $oNewNode = $oIE.document.createElement('Style')
        $oNewNode.setAttribute('type', 'text/css');
        Local $oHead = $oIE.document.head
        $oHead.insertBefore($oNewNode, $oHead.childNodes.Item(1))
        $oNewNode.innerText = $sCSS_Styles
    EndIf


    Local $sHTML_Content = _IEDocReadHTML($oIE)
    Local $hFileOpen_CSSExample = FileOpen($sHTML_FileFullPath, $FO_OVERWRITE + $FO_CREATEPATH + $FO_UTF8)
    FileWrite($hFileOpen_CSSExample, $sHTML_Content)
    FileClose($hFileOpen_CSSExample)


EndFunc   ;==>_IE_SaveToFile

; User's COM error function. Will be called if COM error occurs
Func _My_ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite(@ScriptFullPath & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_My_ErrFunc

 

Edited by mLipok
url changed in example, again.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

I presume you have read the following for some insight.

https://en.wikipedia.org/wiki/MHTML

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

  Reveal hidden contents

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Posted

Thanks for the link.

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

No worries, Wikipedia tends to be my first port of call theses days, just to get the basics on an interest.

I had it in my mind, that I had heard that MHTML was just some kind of fancy zip archive, and I wanted to confirm that before mentioning it to you. Unfortunately I didn't find any mention of that during my quick look.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

  Reveal hidden contents

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Posted

My TODO short list:

  1. get all image to disc
  2. <img alt="Embedded Image" src="data:image/png;base64, ......

:)

Question:

How I can encode jpg file to Base64 - this time I please about AutoIt working solution  .

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)
  On 10/30/2015 at 10:02 AM, TheSaint said:

I had it in my mind, that I had heard that MHTML was just some kind of fancy zip archive, and I wanted to confirm that before mentioning it to you. Unfortunately I didn't find any mention of that during my quick look.

All web content can be saved as a single MHT file,

EDIT:
and this is exactly what I'm trying to do.
Need some help:

  On 10/30/2015 at 10:58 AM, mLipok said:

Question:

How I can encode jpg file to Base64 - this time I please about AutoIt working solution  .

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 10/30/2015 at 11:00 AM, mLipok said:

All web content can be saved as a single MHT file,

More correctly speaking, a container file, as ZIP (ISO, etc) is a container file ... hence the notion they may be similar.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

  Reveal hidden contents

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...