我想從多個網站存檔集合。我希望能夠維持他們是某種組織。所以將它們存儲在鏡像目錄結構中是理想的。下面是我嘗試鏡像網站下載特定的文件類型與BASH
wget -m -x -e robots=off --no-parent --accept "*.ext" http://example.com
當使用「-m」選項它有它去多遠任何限制嗎? (將它徘徊斷了的網站?永遠繼續?)如果是這樣,是它更好地使用
wget -r -x -e robots=off --no-parent --accept "*.ext" --level 2 http://example.com
這是做到這一點的最合理的方式是什麼?我知道「wget」有一個--spider選項,它是否穩定?
編輯
這是我已經找到了解決辦法。
我正在查找的文件被標記並存儲在服務器端的單個dir
中。當嘗試變化wget
。我能夠獲得鏈接和各種文件的結構,但是我一直在使用循環運行鏈接時遇到問題。所以我想出了這個工作。它有效,但速度很慢。有關如何提高效率的任何建議?
的網站&文件,我試圖讓
home
├──Foo
│ ├──paul.mp3
│ ├──saul.mp3
│ ├──micheal.mp3
│ ├──ring.mp3
├──Bar
├──nancy.mp3
├──jan.mp3
├──mary.mp3
所以首先我創建的結構, 與我想
taglist.txt
foo
bar
文件的標籤文件
劇本
#!/bin/bash
#this script seems to work until the download part
URL="http://www.example.com"
LINK_FILE=taglist.txt
while read TAG; do
mkdir "$TAG"
cd "$TAG"
# Get the URLs from the page
wget -q $URL/$TAG -O - | \tr "\t\r\n'" ' "' | \grep -i -o '<a[^>]\+href[ ]*=[ \t]*"\(ht\|f\)tps\?:[^"]\+"' | \sed -e 's/^.*"\([^"]\+\)".*$/\1/g' > tmp.urls.txt
# Clean and sort URLs
grep -i 'http://www.example.com/storage_dir/*' tmp.urls.txt | sort -u > tmp.curls.txt
# Download the page with the URL
while read TAPE_URL; do
#wget -r -A.mp3 $TAPE_URL
wget -O tmp.$RANDOM $TAPE_URL
done <tmp.curls.txt
# Find all the .mp3 links in the files
grep -r -o -E 'href="([^"#]+)[.mp3]"' * | cut -d'"' -f2 | sort | uniq > $TAG.mp3.list
# Clean Up
rm tmp.*
# Download the collected URLs
wget -i $TAG.mp3.list
cd ..
done <"$LINK_FILE"