1.

Solve : Parsing from a web source?

Answer»

Is it possible to take lines of text off a web source using a batch file? If so, how would you do it?

ThanxI don't know whether that can be done, but I would think this question is relevant. Would the exact format of the web page always be the same? In other WORDS, would the text always be exactly in the same place/position on the page? Does this make sense?You can load the site down with "wget". (Gnu package).
A very powerful command. :-)
Parsing the text is another thing...

hope it helps
uliYes, the format would always be the same. It be setup like...

c:\windows\test.txt
c:\windows\system32\test.txt
...

and the list would continue on. It's going to be used to help stop spyware from running by using the cacls command to deny permission. Right now I'm taking the lines off a text file but it would be far more effective if I could take them off a web source if the user should choose to do so.

This is my current code.

Code: [Select]for /f "delims=" %%a in ('type caclslist.txt') do echo y|cacls.exe "%%a" /p guest:n|find /i "processed">>caclslog.log 2>NUL
How would I implement the wget command? I put it in but it said it was an invalid command. Is there something else I would have to download? If so I'm trying to find something that anybody can use without having to download anything new.

Thanx in advance for you're helpYes, WGET is an AWESOME tool, but it does not come with Windows. It is actually a Unix / Linux tool, but they have a version for Windows that you can download from http://unxutils.sourceforge.net/ .

You can use it like:
wget http://www.domain.com/source.html

Then it will depend on the format of the file on how you want to parse / extract lines from it. The example you gave appears to be a text file, and not a "web" file, like HTML.

To parse the file you can use a FOR loop with the SKIP param, and FIND or FINDSTR to look for your text to output or save to a file.Kinda figured that it would something I had to download. Is there any way I can do it without having to download something?

Also, I know it's a text file. I just put that there to show what I'm using to see if you had any ideas on what would need to change to make it WORK properly.If you have a Windows machine, you can use VBScript which came free with your OS. You can script your browser to select data on a web page and utilize the clipboard to hold the data before dumping it in a file.

The example below GETS a new HOSTS file from the internet.

Code: [Select] Const ForWriting = 2
Const TristateUseDefault = -2
Const OverWrite = True

Set objIE = CreateObject("InternetExplorer.Application")
Set fso = CreateObject("Scripting.FileSystemObject")

objIE.Navigate("http://www.mvps.org/winhelp2002/hosts.txt")
Do Until objIE.ReadyState = 4
WScript.Sleep 100
Loop
objIE.document.parentwindow.clipboardData.SetData "text", objIE.document.body.Innertext

Set f = fso.GetFile("c:\windows\system32\drivers\etc\HOSTS")
Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)
ts.Write objIE.Document.ParentWindow.ClipboardData.GetData("text")

ts.Close
objIE.Quit
Set objIE = Nothing

After saving the script with a vbs extension, you can run from the command line as cscript scriptname.vbs

Hope this helps. 8-)

In the example above, you will never see the browser as it's never made visible.



Discussion

No Comment Found