从某个地方下载内容使用 wget

从某个地方下载内容使用 wget

我正在尝试从某个 ImageBam 画廊下载所有图像。我尝试这样做:

wget -P pics -H -nd -r -A '.jpg,.jpeg,.png,.gif,' -erobots=off http://www.imagebam.com/gallery/hwtfu6m7es3gun1emmpy2uheohrcckmt/

但它下载了整个网站;我所需要的只是某个内容<div>,其中包括缩略图和原始图像。是否可以创建一个脚本来下载一个网站<div>而不是整个网站的内容?

答案1

这个问题很困难,因为完整的图片不在父级树下,因此很难将这些路径与站点上的任何其他路径区分开来。此外,指向完整图片的链接实际上是指向嵌入了全分辨率图片的页面的链接。可能有更优雅的解决方案,但这里有一种可行的方法。

#!/bin/bash
wget -np http://www.imagebam.com/gallery/hwtfu6m7es3gun1emmpy2uheohrcckmt/
grep HTML-Code index.html > html_code
grep -E -o 'http://thumbnails[^"]+' html_code > thumb_urls
grep -E -o 'http://www[^"]+' html_code > image_pages
wget -i thumb_urls
wget -P image_pages_dir -i image_pages
for file in image_pages_dir/*
do
    echo $file
    grep -m 1 -o -E 'http://.*jpg' $file >> full_image_urls
done
wget -i full_image_urls

相关内容