How to read web page source?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Laakkus
Posts: 2
Joined: 01 Nov 2011 15:52

How to read web page source?

#1 Post by Laakkus » 01 Nov 2011 16:13

Hello.

I need to read (and search for a string) a web page's source. Any help appreciated.

The search part i think i can handle, but haven't been able to find anything to get the web page source to a string/array/anything that i can manipulate.

I'd prefer a solution WITHOUT any external programs if possible.

jeb
Expert
Posts: 1059
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: How to read web page source?

#2 Post by jeb » 01 Nov 2011 16:26

IMHO with pure batch this isn't possible, but you could use vbscript/jscript.
And use this from a batch file.

Code: Select all

for /F "usebackq tokens=1-3 delims=," %%a in (`cscript /nologo GetHtml.vbs http://google.com/`) DO (
  echo(%%a
)


Code: Select all

'GetHTML.vbs
URL = WScript.Arguments.Item(0)

Set WshShell = WScript.CreateObject("WScript.Shell")

Set http = CreateObject("Microsoft.XmlHttp")
http.open "GET", URL, FALSE
http.send ""
WScript.echo http.responseText


You could even embedd the vbs into your batch file if necessary.

jeb

aGerman
Expert
Posts: 4736
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How to read web page source?

#3 Post by aGerman » 01 Nov 2011 16:32

There are third party tools like Wget or cURL. By default you can't do that via batch.
Otherwise you could use VBScript or JScript (as jeb has been shown) if you need to get the source text without external tools.

Regards
aGerman

Laakkus
Posts: 2
Joined: 01 Nov 2011 15:52

Re: How to read web page source?

#4 Post by Laakkus » 01 Nov 2011 17:14

Thank you both for your quick replies!
I'll get back to you if I run into more trouble ;)

darioit
Posts: 230
Joined: 02 Aug 2010 05:25

Re: How to read web page source?

#5 Post by darioit » 14 Nov 2011 10:31

OK aGerman thank you, but can I parse my saved html file previously saved?

Post Reply