Skip to content

Instantly share code, notes, and snippets.

@mlhaufe
Created January 6, 2012 00:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlhaufe/1568244 to your computer and use it in GitHub Desktop.
Save mlhaufe/1568244 to your computer and use it in GitHub Desktop.
Getting html details (VBScript)
'Reference: <http://www.visualbasicscript.com/tm.aspx?high=&m=95638&mpage=1>
Option Explicit
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Dim files : Set files = fso.GetFolder("C:\test\").Files
Dim file
For Each file In files
If file.Type = "Firefox Document" Then '<-- update for your system
Dim doc : Set doc = CreateObject("htmlfile")
doc.write fso.OpenTextFile(file.Path).ReadAll()
WScript.Echo doc.title
doc.title = doc.title & " (Modified)"
WScript.Echo doc.documentElement.outerHTML
End If
Next
@iisboy
Copy link

iisboy commented Dec 3, 2020

this code support all version os?

@mlhaufe
Copy link
Author

mlhaufe commented Dec 3, 2020

@iisboy I forgot what this script was created for as the referenced website no longer exists. This script was first written for Windows 2000 and still works in Windows 10.

If you can use Powershell instead then you should:

ls -Recurse *.html | % {
  $html = New-Object -Com 'HTMLFile'
  $html.IHTMLDocument2_write($(gc $_ -Raw))
  # $html is the DOM so the normal properties and methods work
  Write-Host "Path $($_.FullName)"
  Write-Host "Title: $($html.title)"
}

@iisboy
Copy link

iisboy commented Dec 4, 2020

@iisboy I forgot what this script was created for as the referenced website no longer exists. This script was first written for Windows 2000 and still works in Windows 10.

If you can use Powershell instead then you should:

ls -Recurse *.html | % {
  $html = New-Object -Com 'HTMLFile'
  $html.IHTMLDocument2_write($(gc $_ -Raw))
  # $html is the DOM so the normal properties and methods work
  Write-Host "Path $($_.FullName)"
  Write-Host "Title: $($html.title)"
}

thanks for your reply. i want help for you a copy of code ,i test in windows 7 have a little bug,this is below:

`dim strJson,myJson

strJson="{  ""access_token"":""ACCESS_TOKEN"",  ""expires_in"":7200,  ""refresh_token"":""REFRESH_TOKEN"",  ""openid"":""OPENID"",  ""scope"":""SCOPE"" }"
set doc = CreateObject("htmlfile")
doc.write ""
set JSON = doc.frames.JSON
set obj = JSON.parse(strJson)
'myJson=JSON.stringify(obj)

Response.Write obj.access_token

retrun value :
Microsoft VBScript ����ʱ���� ���� '800a01b6'

����֧�ִ����Ի򷽷�: 'doc.frames.JSON'

/123_fun/1.asp���� 13`

@mlhaufe
Copy link
Author

mlhaufe commented Dec 9, 2020

@iisboy I believe "htmlfile" is equivalent to Internet Explorer 6, and therefore supports ECMAScript version 3. Which means no JSON object.

Perhaps using a 3rd party library would help?

@iisboy
Copy link

iisboy commented Dec 14, 2020

@iisboy I believe "htmlfile" is equivalent to Internet Explorer 6, and therefore supports ECMAScript version 3. Which means no JSON object.

Perhaps using a 3rd party library would help?

@mlhaufe:thanks for your help ,i just make a test .the result:in win7+IE10,or in 2012+,my code run all in well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment