I got a requirement like, need to get few content from a website and i have to save that in a .txt file using batch scripting.
@echo off
echo.>"D:\Jai\dblank.txt"
by using above batch code i can only create a file in a location along with this i want to give the browser content in that .txt file. I am very new to batch scripting.
Set Arg = WScript.Arguments
set WshShell = createObject("Wscript.Shell")
Set Inp = WScript.Stdin
Set Outp = Wscript.Stdout
if LCase(Arg(0)) = "web" or LCase(Arg(0)) = "http" then
HttpGet
Elseif LCase(Arg(0)) = "remhtml" or LCase(Arg(0)) = "tags" then
RemoveHTMLTags
End If
Sub HttpGet
On Error Resume Next
Set File = WScript.CreateObject("Microsoft.XMLHTTP")
File.Open "GET", Arg(1), False
File.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 1.1.4322; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C; .NET4.0E; BCD2000; BCD2000)"
File.Send
txt=File.ResponseText
'Putting in line endings
Outp.write txt
If err.number <> 0 then
Outp.writeline ""
Outp.writeline "Error getting file"
Outp.writeline "=================="
Outp.writeline ""
Outp.writeline "Error " & err.number & "(0x" & hex(err.number) & ") " & err.description
Outp.writeline "Source " & err.source
Outp.writeline ""
Outp.writeline "HTTP Error " & File.Status & " " & File.StatusText
Outp.writeline File.getAllResponseHeaders
Outp.writeline LCase(Arg(1))
End If
End Sub
Sub RemoveHTMLTags
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = 0
ie.Silent = 1
ie.Navigate2 "file://" & FilterPath & "Filter.html"
Do
wscript.sleep 50
Loop Until ie.document.readystate = "complete"
ie.document.body.innerhtml = Inp.readall
Outp.write ie.document.body.innertext
' ie.quit
End Sub
To use
General Use
Filter is for use in a command prompt. Filter.vbs must be run with cscript.exe. If you just type filter it will run a batch file that will do this automatically.
filter subcommand [parameters]
Filter reads and writes standard in and standard out only. These are only available in a command prompt.
filter <inputfile >outputfile
filter <inputfile | other_command
other_command | filter >outputfile
other_command | filter | other_command
Web
filter web webaddress
filter ip webaddress
Retrieves a file from the web and writes it to standard out.
webaddress - a web address fully specified including http://
Example
Gets Microsoft's home page
cscript //nologo filter.vbs web http://www.microsoft.com
Tags
filter tags
Removes HTML tags from text.
Example
cscript //nologo filter.vbs web http://www.microsoft.com | cscript //nologo filter.vbs tags