开发者

Wget Output in Recursive mode

开发者 https://www.devze.com 2023-02-15 16:24 出处:网络
I am using wget -r to downlo开发者_如何学Cad 3 .zip files from a specified webpage. Here is what I have so far:

I am using wget -r to downlo开发者_如何学Cad 3 .zip files from a specified webpage. Here is what I have so far:

 wget -r -nd -l1 -A.zip http://www.website.com/example

Right now, the zip files all begin with abc_*.zip where * seems to be a random. I want to have the first downloaded file to be called xyz_1.zip, the second to be xyz_2.zip, and the third to be xyz_3.zip.

Is this possible with wget?

Many thanks!


I don't think it's possible with wget alone. After downloading you could use some simple shell scripting to rename the files, like:

i=1; for f in abc_*.zip; do mv "$f" "xyz_$i.zip"; i=$(($i+1)); done


Try to get a listing first and then download each file separately.

let n=1
wget -nv -l1 -r --spider http://www.website.com/example 2>&1 | \
egrep -io 'http://.*\.zip'| \
while read url; do 
    wget -nd -nv -O $(echo $url|sed 's%^.*/\(.*\)_.*$%\1%')_$n.zip "$url"
    let n++
done


I don't think there is a way you can do it within a single wget command.

wget does have a -O option which you can use to tell it which file to output to, but it won't work in your case because multiple files will get concatenated together.

You will have to write a script which renames the files from abc_*.zip to xyz_*.zip after wget has completed.

Alternatively, invoke wget for one zip file at a time and use the -O option.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号