Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to mirror a website.

It follows a simple scheme of .htm files but there is one catch. Each file contains the following line:

<img width="100%" src="http://DOMAIN.org/CREATE_IMAGE.php">

I need to download this image, but httrack and wget both ignore the script outputs when downloading a file.

The php script does not take any parameters. It determines which image to output internally. Each .htm file gets a different output. So I can't simply call the php file. It needs to be downloaded as some kind of dependency of the corresponding .htm file.

How can I configure wget or httrack or really any other tool to get what I need?

share|improve this question

1 Answer 1

You can't download and run the .php since it is supposed to run server-side.

If the website is such as:

<html>
...
<img width="100%" src="http://DOMAIN.org/CREATE_IMAGE.php">
...
</html>

When you get the page source you can't actually see that (client-side). What you should see is:

<html>
...
<img width="100%" src="http://DOMAIN.org/IMAGE_LINK_GENERATED_BY_THE_PHP_SCRIPT">
...
</html>

You could then wget the html, parse it, and download the image. You have to either know the pattern of the filename or the possible extensions. If you don't, you can iterate over a list of possible extensions. For only one image it should look something like this:

# Get the html for us to parse
wget http://DOMAIN.org/index.html -O index.html
# List of common image extensions
exts=("png" "jpg" "jpeg" "bmp" "gif")
for ext in ${exts[@]}
do
    # Parse the html looking for an image
    # You'll have to adapt the regex, of course
    # man grep to see what each letter stands for
    img=`grep -shoiP "DOMAIN\.org/.+\.${ext}" index.html`
    if [ "$img" = "" ]
    then
        continue
    else
        break
    fi
done
wget $img

Of course you'll have to adapt that.

share|improve this answer

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.