pocoyo 写了:我靠 受不了了。。。。tenzu 写了:LS的头像。。。
![:em03 :em03](./images/smilies/em03.gif)
![:em20 :em20](./images/smilies/em20.gif)
pocoyo 写了:我靠 受不了了。。。。tenzu 写了:LS的头像。。。
叶大,不是所有的网页的图片都是<img src=xxx>的oneleaf 写了:ok,给个简单的py代码: 全选
import urllib,re u = 'http://forum.ubuntu.org.cn/' html = urllib.urlopen(u).read() li=re.findall('img src="*.*?"', html, re.S) for item in li: print item item = item.replace('img src="','').replace('"','') urllib.urlretrieve(('' if item.find('http://')==0 else u)+'/'+item,item.split('/')[-1])
代码: 全选
] ls -ld //
代码: 全选
#!/bin/bash
(($#!=1)) && echo "need a url " && exit
curl $1 | grep -o "img src=\"[^\"]*\"" | cut -f 2 -d'"' | wget -i -
代码: 全选
#!/bin/sh
# -- picture.sh --
BASE_URL=$1
FILE="file.html"
gethtml() {
wget -O $FILE $BASE_URL
}
if [ -z $1 ]; then
echo "Please give the url."
else
gethtml
fi
pic_url=`grep -o -P '(\/\w+)+\.(jpg|gif|png)' $FILE | \
sed 's/^\///'`
for i in $pic_url; do
last_url=${BASE_URL}/$i
echo $last_url
#wget $last_url
done
是re匹配的问题,你修改下匹配模板就可以了。tusooa 写了:叶大,不是所有的网页的图片都是<img src=xxx>的oneleaf 写了:ok,给个简单的py代码: 全选
import urllib,re u = 'http://forum.ubuntu.org.cn/' html = urllib.urlopen(u).read() li=re.findall('img src="*.*?"', html, re.S) for item in li: print item item = item.replace('img src="','').replace('"','') urllib.urlretrieve(('' if item.find('http://')==0 else u)+'/'+item,item.split('/')[-1])
![]()
![]()
,Xhtml标准要求有alt,吾喜欢<img alt="xxx" src="xxx" />这个脚本就够不到了。
匹配连续n多个'"',确实不合理。
吾的长,是为了速度(cURL很快)和质量。(前面的脚本统统不能搞到<img alt="xxx" src="xxx" />这样的)