# How To Save Web Page From Command Line



## Somnamna (Jun 3, 2004)

I need to download a web page as "Web page, HTML only" and save it to my hard drive. The problem is, it needs to be done from a command line - not by me sitting at the computer reading and clicking.

Here's the situation: I get emails at all times, day & night, telling me that a file is available on a web site. The emails contain a link to the "download page".

The "download page" has a link to the file. It is that link that I need to extract from the "download page", which I can do if I can save the "download page" to my hard drive.

Any ideas gratefully received.


----------



## MMJ (Oct 15, 2006)

Think you need a 3rd party program.

http://www.google.com/#hl=en&q=wget+windows


----------



## Somnamna (Jun 3, 2004)

MMJ said:


> Think you need a 3rd party program.
> 
> http://www.google.com/#hl=en&q=wget+windows


Yes, I've tried wget, but I can't get it to work with the web site.

The page I want to download the source of is: http://www.website.com/details.php?id=123456

(I've changed the name and details).

It may be that the "?" in the URL is causing a problem. I've tried changing it to "%3F", but no luck.

If anyone can give the correct syntax to get this single page source, I'd be very grateful.

Edit:

I've just tried WinWget and got the same error, so at least I know I was creating the same command line as WinWget does.

I think the problem may be because I need to log in. When I put the URL into my browser, it works, but I am logged in. If I log out and put the same URL in, I get a "not logged in" error page.

So I must check out how to added username and password to the Wget line.


----------



## MMJ (Oct 15, 2006)

Using http://www.christopherlewis.com/WGet/WGetFiles.htm I downloaded any page very easily, even with a query string.


```
wget "http://www.google.com/#hl=en&source=hp&q=asd"
```
Are you getting an error message?


----------



## Somnamna (Jun 3, 2004)

MMJ said:


> Using http://www.christopherlewis.com/WGet/WGetFiles.htm I downloaded any page very easily, even with a query string.
> 
> 
> ```
> ...


Yes - here's the end of the log:


> Resolving www.xxxxxxx.xxx... 80.xxx.xxx.xxx
> Connecting to www.xxxxxxx.xxx[80.xxx.xxx.xxx]:80... connected.
> HTTP request sent, awaiting response... 404 Not Found
> 03:54:25 ERROR 404: Not Found.


The 404 error message confused me. I'm sure I need to log in or send my user name and password. I think wget can do this, and I need to find the correct syntax.


----------



## Somnamna (Jun 3, 2004)

The best solution I've found is to use the "iMacros" extension for Firefox which allows you to write a macro to save the current page, as well as do lots of other things.

Can be got here: http://www.iopus.com/imacros/firefox/


----------



## jlhaslip (Nov 21, 2009)

<?php
$source = file_get_contents('http://www.google.com');
echo $source;
?> 
PLay with the file_get_contents function. You should be able to open a text file and save the page contents inside it instead of an echo.


----------

