shell脚本下载网页图片

和大家分享一个shell脚本写的图片抓取器。
使用方法:
img_downloader.sh。
使用时在shell下输入:
./img_downloader.sh www.baidu.com -d images
该shell脚本就会把百度首页上的图片下载下来。

代码:

#!/bin/bash
if [ $# -ne 3 ];
then
 echo "Usage: $0 URL -d DIRECTORY"
 exit -1
fi
for i in {1..4}
do
 case $1 in
 -d) shift; directory=$1; shift;;
    *) url=${url:-$1};shift;
esac
done
mkdir -p $directory
baseurl=$(echo $url | egrep -o "https?://[a-z.]+")
echo "$baseurl"
curl -s $url | egrep -o "<img src=[^>]*>" |
sed ‘s/<img src=\"\([^"]*\).*/\1/g‘ > /tmp/$$.list
sed -i "s|^/|$baseurl/|" /tmp/$$.list
cd $directory;
while read filename
do
 curl -s -O "$filename" --silent
done < /tmp/$$.list
时间: 2024-08-01 07:58:43

shell脚本下载网页图片的相关文章

c# 下载网页图片

也是比较老的东西了 最近用到 记录下以免以后忘了 要下载图片首先要有图片地址 要有图片地址就要先把网页下下来分析下URL 下载网页一般用两种方法 1,用 system.net.webclient using System.Net; using System.Windows.Forms; string url = "http://www.cnblogs.com"; string result = null; try { WebClient client = new WebClient()

Python下载网页图片

#coding:utf-8 import requests from bs4 import BeautifulSoup import re DownPath = "/jiaoben/python/meizitu/pic/" import urllib head = {'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'} TimeOu

python爬虫.3.下载网页图片

目标,豆瓣读书, 下载页面书籍图片. import urllib.request import re #使用正则表达式 def getJpg(date): jpgList = re.findall(r'(img src="http.+?.jpg")([\s\S]*?)(.+?.alt=".+?.")',date) return jpgList def downLoad(jpgUrl,sTitle,n): try: urllib.request.urlretrieve

python多线程下载网页图片并保存至特定目录

#!python3 #multidownloadXkcd.py - Download XKCD comics using multiple threads. import requests import bs4 import os import threading # os.mkdir('xkcd', exist_ok=True) # store comics in ./xkcd if os.path.exists('xkcd'): print("xkcd is existed!")

用shell脚本打ipa包

转载出处: xcode自动打ipa包脚本 | webfrogshttp://blog.nswebfrog.com/2012/09/19/buildipa/ shell脚本下载 : webfrogs/xcode_shell · GitHubhttps://github.com/webfrogs/xcode_shell

shell脚本——自动识别图片验证码

Linux与Shell刚入门学习,写的东西在大多数人看来很浅,其实只为自己的学习总结. 如果有大牛对我写的东西指点一二,更是感激不尽! 近来经常用Archlinux上一个国外的免费VPN,速度还不错,就是每天会变一次密码,每天都要上主页去看一下最新的密码,久了也感觉麻烦,所以就想点懒招(我这人有点懒)-- 经观察,密码验证图为4个数字,分别由a.jpg.b.jpg.c.jpg.d.jpg组成,下载图片后用diff和cmp比对后发现只要是同样数字,都是同一张图片,不管是叫a还是叫b还是叫c 所以我

FTP定时批量下载文件(SHELL脚本及使用方法 ) (转)

ftp -v -d -i -n -g [主机名] ,其中-v 显示远程服务器的所有响应信息:-n 限制ftp的自动登录,即不使用:.n etrc文件:-d 使用调试方式:-g 取消全局文件名.http://blog.itpub.net/20943428/viewspace-630467/ 1. 脚本实例 将以下脚本保存为 getftp.sh #!/bin/bash datesign=`date -d -95day +%Y%m%d` ftp -nv 12.2.2.28 <<!FTPRUN use

下载Google官方/CM Android源代码自动重新开始的Shell脚本

国内由于某种原因,下载CM或Google官方的Android源代码总容易中断.总看着机器,一中断就重新执行repo sync还太麻烦,所以我特意编写了一段shell脚本(download.sh).通过获取shell最后返回的状态码来决定是否再次执行repo sync命令. #!/bin/bash echo "======start repo sync======" repo sync # 第一次下载android源代码 while [ $? != 0 ]; do echo "

一个用于批量下载网络图片的Shell脚本

By Long Luo 最近为了做好一个天气预报的项目,需要从Yahoo下载一些天气图标,但是由于图标比较多,有80多张.图标是存储在Yahoo Image网站上的. 迅雷不支持https的下载,虽然可以在浏览器下载,但是在浏览器下载太慢,于是写了一个批量下载图片资源的Shell脚本,完美的解决了这个问题. Yahoo天气图标的地址规则如下:`https://s.yimg.com/zz/combo?a/i/us/nws/weather/gr/` + 图标名称 比如: 我使用了2种方法,解决了下载