Discussion:
retrieve HTML from a website using VBScript
(too old to reply)
fher182
2006-05-05 03:03:52 UTC
Permalink
I need help for creating a VBScript that can retrieve HTML from a given
web site (perhaps typing the URL in an Inputbox) and the store that in
my local computer.(the HTML)
Any Idea?
Thanks
McKirahan
2006-05-05 03:18:16 UTC
Permalink
Post by fher182
I need help for creating a VBScript that can retrieve HTML from a given
web site (perhaps typing the URL in an Inputbox) and the store that in
my local computer.(the HTML)
Any Idea?
Run Fetch.vbs then enter a URL; the file will be saved as
"c:\temp\Fetched". Rename it afterwards.

Note that a URL doesn't have to include a filename;
for example, http://www.google.com/

Option Explicit
Const cVBS = "Fetch.vbs"
Const cOUT = "c:\temp\Fetched"
Dim strURL
strURL = InputBox("Enter a URL",cVBS)
MsgBox Fetch(strURL,cOUT),vbInformation,cVBS

Function Fetch(xURL,xOUT)
On Error Resume Next
Err.Clear
Dim b
With CreateObject("Microsoft.XMLHTTP")
.Open "GET",xURL,False
.Send
b = .ResponseBody
If Err.Number <> 0 Or .Status <> 200 Then
Fetch = False
Exit Function
End If
End With
With CreateObject("ADODB.Stream")
.Type = 1
.Open
.Write b
.SaveToFile xOUT,2
End With
Fetch = Err.Number = 0
End Function
fher182
2006-05-05 07:30:28 UTC
Permalink
any way to do something similar using xmlhttpserver object?
Miyahn
2006-05-05 05:03:23 UTC
Permalink
Post by fher182
I need help for creating a VBScript that can retrieve HTML from a given
web site (perhaps typing the URL in an Inputbox) and the store that in
my local computer.(the HTML)
Any Idea?
Not a straight answer.

I use the following HTA to add new context menu to the anchors in the page
which is showed by IE.
The menu save the entire page as a web archive file (*.mht) to the folder,
%userprofile%\My Documents\HomePages\

<!-- 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>
--
Miyahn (Masataka Miyashita) JPN
Microsoft MVP for Microsoft Office - Excel(Jan 2006 - Dec 2006)
***@nifty.ne.jp
Fosco
2006-05-05 05:04:10 UTC
Permalink
"fher182"
Post by fher182
I need help for creating a VBScript that can retrieve HTML
McKirahan has post a Microsoft.XMLHTTP sample here an
internetexplorer.application :

' (innerText & outerHtml)

x = TextFromHTML("http://www.google.com/")
'WScript.Echo x
Function TextFromHTML(URL)
set ie = createobject("internetexplorer.application")
ie.navigate URL
do until ie.readystate = 4 : wscript.sleep 10: loop
TextFromHTML = ie.document.body.outerHtml
ie.quit
End Function
filename = "google.html"
Set fso = CreateObject("Scripting.FileSystemObject")
Set newf = fso.createtextfile(filename)
newf.WriteLine x

x = TextFromHTML("http://www.google.com/")
'WScript.Echo x
Function TextFromHTML(URL)
set ie = createobject("internetexplorer.application")
ie.navigate URL
do until ie.readystate = 4 : wscript.sleep 10: loop
TextFromHTML = ie.document.body.innerText
ie.quit
End Function
filename = "google.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set newf = fso.createtextfile(filename)
newf.WriteLine x

--
Fosco
fher182
2006-05-05 07:29:33 UTC
Permalink
Thanks Iliked your first coment, du not undertand the second one.
Do you have any experience using xmlhttpserver object?
Fosco
2006-05-06 02:14:29 UTC
Permalink
"fher182"
Post by fher182
Do you have any experience using xmlhttpserver object?
http://www.google.it/search?hl=it&q=xmlhttpserver+object%2Bfaq&meta=

http://www.google.it/search?hl=it&q=xmlhttp+object%2Bfaq&btnG=Cerca&meta=

--
Fosco
fher182
2006-05-07 00:58:42 UTC
Permalink
Thanks but English will help too, italian is cool anyway, thanks man
Fosco
2006-05-07 02:41:27 UTC
Permalink
"fher182"
Post by fher182
Thanks but English will help too, italian is cool anyway, thanks man
?????????

it's ALL in English here if I click on the 2 links:
http://www.google.it/search?hl=it&q=xmlhttpserver+object%2Bfaq&meta=
http://www.google.it/search?hl=it&q=xmlhttp+object%2Bfaq&btnG=Cerca&meta=


anyway open your google version and put xmlhttpserver object+faq
and xmlhttp object+faq in the search box

This is a great tool made by DaleHohm in autoit to fetch web pages :
launch it and wait :
http://www.filegone.com/1wt8

read more here :
http://www.autoitscript.com/forum/index.php?showtopic=13398

--
Fosco

Fosco
2006-05-05 05:19:20 UTC
Permalink
"fher182"

or 2 lines of code : (NOT wsh/vbs)

from :
http://www.hiddensoft.com/autoit3/

; [code]

$get = InputBox("Test","","http://www.google.com")
InetGet($get,"c:\file.htm",1)
InetGet("http://www.mozilla.org", "C:\mozilla.html")

--
Fosco
Alexander Mueller
2006-05-05 06:12:07 UTC
Permalink
Post by fher182
I need help for creating a VBScript that can retrieve HTML from a given
web site (perhaps typing the URL in an Inputbox) and the store that in
my local computer.(the HTML)
Any Idea?
Thanks
wget -O <uri_local_storage> <remote_uri>

http://www.gnu.org/software/wget/


MfG,
Alex
Continue reading on narkive:
Loading...