例子,python采集图片实例。
复制代码 代码示例:
#!/bin/python
import urllib
import re
import time
import random
url = "http://www.jb200.com/jiu/all/whole/1"
content = urllib.urlopen(url).read()
n = re.findall(r"<a href="/jiu/all/whole/d+".*?>(d+)</a>",content);
maxpage = int(n[len(n)-1]);
for i in range(1,maxpage):
url = url = "http://www.jb200.com/jiu/all/whole/" + str(i)
content = urllib.urlopen(url).read()
m = re.findall(r"data-original="(.*?)"",content)
if m:
for k in m:
index = k.rindex('_',0);
j = k[0:index]
con = urllib.urlopen(j).read();
filename = str(time.time())+".jpg"
f = file(filename,"wb");
f.write(con);
f.close();
else:
print 'not search' </span>