Reading text from url [ SOLVED ]

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
htb
Posts: 7
Joined: 15 Aug 2012 21:55

Reading text from url [ SOLVED ]

#1 Post by htb » 15 Aug 2012 22:00

I'm new to this forum so first I want to say Hi to every one :)

I want to ask one question. I found this code here

Code: Select all

@echo off
echo Set objHTTP = CreateObject("MSXML2.XMLHTTP")>>ip.vbs
echo Call objHTTP.Open("GET", "http://checkip.dyndns.org", False)>>ip.vbs
echo objHTTP.Send()>>ip.vbs
echo strHTML = objHTTP.ResponseText>>ip.vbs
echo wscript.echo strHTML>>ip.vbs

for /f "tokens=7 delims=:<" %%a in ('cscript /nologo "ip.vbs"') do set ip=%%a
echo %ip:~1%
pause


Is it posible to make it to read lets say from .txt
Example http://mysite.com/text.txt
I try but I cant make it. Can somebody help me.
Thanks
Last edited by htb on 16 Aug 2012 01:29, edited 1 time in total.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Reading text from url

#2 Post by foxidrive » 15 Aug 2012 22:31

What do you want to read from the website?

A third party tool called wget.exe will read web pages.

htb
Posts: 7
Joined: 15 Aug 2012 21:55

Re: Reading text from url

#3 Post by htb » 15 Aug 2012 22:36

Yes, but after this code can display the info from the page ( you'r IP ) can it display some text from page?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Reading text from url

#4 Post by foxidrive » 15 Aug 2012 22:45

Here, try this. If you want something specific then describe what you want exactly.

Code: Select all

@echo off
echo Set objHTTP = CreateObject("MSXML2.XMLHTTP")>>ip.vbs
echo Call objHTTP.Open("GET", "http://www.dostips.com/forum/viewtopic.php?f=3&t=3656&view=unread#unread", False)>>ip.vbs
echo objHTTP.Send()>>ip.vbs
echo strHTML = objHTTP.ResponseText>>ip.vbs
echo wscript.echo strHTML>>ip.vbs

for /f "delims=" %%a in ('cscript /nologo "ip.vbs"') do echo %%a
del ip.vbs
pause

htb
Posts: 7
Joined: 15 Aug 2012 21:55

Re: Reading text from url

#5 Post by htb » 15 Aug 2012 22:51

The first code I paste when you start it its shows you'r IP that takes it from http://checkip.dyndns.org in the screen.
I'm looking for a way to display text from .txt or .html
Lets say I have http://mysite.com/text.txt and in the .txt file I have " Hello "
When I start it in the place when now its displaying the IP I want to see " Hello "
Thanks

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Reading text from url

#6 Post by foxidrive » 15 Aug 2012 22:54

Did you try the code above?

htb
Posts: 7
Joined: 15 Aug 2012 21:55

Re: Reading text from url

#7 Post by htb » 15 Aug 2012 22:56

Oh yes, sorry very much. My fail :oops:
Can I use some how

Code: Select all

echo %ip:~1%>>IP.txt

I can find a way to make it. Thank you for you time :)

htb
Posts: 7
Joined: 15 Aug 2012 21:55

Re: Reading text from url

#8 Post by htb » 15 Aug 2012 23:02

Sorry for the double post.
I found what I need :)

Code: Select all

@echo off
echo Set objHTTP = CreateObject("MSXML2.XMLHTTP")>>ip.vbs
echo Call objHTTP.Open("GET", "http://link.com/text.txt", False)>>ip.vbs
echo objHTTP.Send()>>ip.vbs
echo strHTML = objHTTP.ResponseText>>ip.vbs
echo wscript.echo strHTML>>ip.vbs

for /f "delims=" %%a in ('cscript /nologo "ip.vbs"') do set ip= %%a
echo %ip:~1%
echo %ip:~1%>>IP.txt
pause

Post Reply