Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to download data from my server using wget.

I send the login details and store the cookie. I then rotate through 50 numbers to copy the data into new files. The saved files are always blank i.e 0kb file size.

My website stores data on individual pages e.g.: (i have changed my actual site name to "mywebsite")

'http://admin.mywebsite.com/index.php/print_view/?html=true&order_id=50

I am trying to rotate through the numbers 50 to 1 and extract the data from each page.

The code I am using is below:

#!/usr/bin/perl

system ("wget --post-data 'username=ghssld&password=ewui394&autologin=1' --cookies=on --keep-session-cookies --save-cookies=cookie.txt 'http://admin.mywebsite.com/index.php/login");

$x = 50;
while ($x <= 1) {
system ("wget --wait=400 --post-data 'html=true&order_id=50' --referer=http://admin.mywebsite.com/ --cookies=on --load-cookies=cookie.txt --keep-session-cookies --save-cookies=cookie.txt 'http://admin.mywebsite.com/index.php/print_view/");

system ("wget --post-data 'html=true&order_id=50' --referer=http://admin.mywebsite.com/ --cookies=on --load-cookies=cookie.txt --keep-session-cookies --save-cookies=cookie.txt 'http://admin.mywebsite.com/index.php/print_view?");
$x++;
}

Can anyone help me modify my code so data is pulled correctly and the saved files are not blank? (I have commented the hyperlink addresses because I'm a new user and I can only post one hyperlink!) Thank you

share|improve this question
    
I just realized this should probably on SO not SF. –  Nathan Adams Dec 15 '10 at 2:48
add comment

1 Answer

First off, the code you posted is using a Perl interpreter which makes 0 sense. The code does look like PHP so the tags are correct.

Second, is there a reason why you need to use wget? I would recommend curl:
http://php.net/manual/en/book.curl.php

If you really need to use wget, this seems like a better job for a simple BASH script.

Otherwise, you need to post more information. I'm not 100% sure, but a tool like wget should spit out error messages if something didn't work correctly.

share|improve this answer
    
Hi Nathan,Thanks for –  James Locke Dec 22 '10 at 16:27
    
Thanks for your advice. I successfully used curl to extract the data i needed. I now need to extract relevant words from a series of the html files by the user. e.g. Name, Address, Mobile and DOB. I would be grateful if you could point me in the right direction so i can write a script that will extract the name, address out of each html file and put the data into a csv/text file for uploading into a spreadsheet. –  James Locke Dec 22 '10 at 16:29
    
That is rather easy with regular expressions, but not a question for serverfault. Post your new code and question on stackoverflow.com. –  Nathan Adams Dec 23 '10 at 13:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.