Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Open URL from batch file and copy the text to a file

Posted on 2014-03-07
9
Medium Priority
?
5,047 Views
Last Modified: 2014-03-11
Hello Experts,

I want to make a batch file which should something like ....

Once run the batch file that should perform the below activities:

Open a URL

copy all the text from the URL
paste it on one text file.


Now when every I run the batch that should do the same operation but if I run 2 times then the text copied will be twice on the same file.

For example i open www.####.com

that URL will have the only say :

ABCEDED

Now when I run it , all the text will be copied to my text file named as test.txt and then when run again this should also do the same thing but if opened the text it should be like below :

output of test.text

time taken <<time when the batch was executed >>:
ABCEDED

time taken <<time when the batch was executed >>:
ABCEDED
0
Comment
Question by:Swadhin Ray
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 36

Expert Comment

by:Kimputer
ID: 39912204
Get wget from sourceforge > http://sourceforge.net/projects/gnuwin32/files/wget/
Get it working on system wide your PC (put it somewhere with the dependency dll's, preferably in system32)
batch file will have the lines:

time < null >> logfile
wget "url"

The trick is to know which file is created (probably index.html but could be slightly different, so test it)

Next is to have the batch file do:

type index.html >> logfile
del index.html

because otherwise wget will add the file again next time with a different filename (adding ".1" or ".2" etc)
0
 
LVL 85

Expert Comment

by:oBdA
ID: 39912312
"Open" and "paste" is not a big deal. What may be problematic is "copy all the text", as it takes megabytes of browser suites to just "display text" coming from a website. If you don't want the html source code, the plain text interesting you might be extractable, but that requires knowledge of the exact source you want.
The script below uses curl.exe (project page http://curl.haxx.se/download.html, direct Windows download http://www.paehl.com/open_source/?download=curl_735_0_ssl.zip. Unzip curl.exe (no dependencies) from the download and put it either into the script's folder or in any folder that's in the path.
@echo off
setlocal enabledelayedexpansion
set OutFile=C:\Temp\test.txt
set URL=http://checkip.dyndns.org/
>>"%OutFile%" echo --------------------------------------------------------------------------------
>>"%OutFile%" echo Source of 'URL', %Date% %Time%
>>"%OutFile%" curl.exe -s -S %URL%
if errorlevel 1 (
	echo "Download of '%URL%' failed!"
) else (
	echo "Download of %URL% successful."
)
>>"%OutFile%" echo --------------------------------------------------------------------------------

Open in new window

0
 
LVL 71

Expert Comment

by:Qlemo
ID: 39912384
VBS and PowerShell have powerful means to parse web page content, so that would be another option.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 16

Author Comment

by:Swadhin Ray
ID: 39912428
@oBda: I tried your solution but when I do it is not selecting all the text that are there when we open in browser :

my output file gets :


--------------------------------------------------------------------------------
Source of 'URL', Fri 03/07/2014 19:23:25.04
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Source of 'URL', Fri 03/07/2014 19:23:51.21
--------------------------------------------------------------------------------

Open in new window

0
 
LVL 85

Expert Comment

by:oBdA
ID: 39912564
That's somewhat not enough.
Is there any output on the screen when you run this? If you started the script using a double-click in Explorer, please open a command prompt, enter "cd /d Path to the script", and then run the script again from there.
What's the output when you enter "curl.exe http://checkip.dyndns.org" in the command prompt?
Are you using a proxy to connect to the internet?
In line 6, there are percent signs missing around "URL", but that's just cosmetic.
0
 
LVL 16

Author Comment

by:Swadhin Ray
ID: 39912643
When I run your script I get the below:

--------------------------------------------------------------------------------
Source of 'URL', Fri 03/07/2014 20:27:37.82
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Source of 'URL', Fri 03/07/2014 20:27:46.64
--------------------------------------------------------------------------------

Open in new window

0
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 39912686
That's the content of the log file; but what's the output in the command prompt window?
Please open a command prompt by entering "cmd.exe" in the run box, then enter "cd /d Path to the script", and then run the script again from there.
What's the output when you enter curl.exe http://checkip.dyndns.org in the command prompt?
Are you using a proxy to connect to the internet?
0
 
LVL 16

Author Comment

by:Swadhin Ray
ID: 39912779
Ok go it ..

But I have another problem ..
My URL is having username and password .
Once login to the URL I need to open another tab and then open another link for which I need to get the data what the provided script is doing
0
 
LVL 16

Author Closing Comment

by:Swadhin Ray
ID: 39920039
thanks this helps a lot.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

596 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question