用python试着简单爬取下360图片的图片
import re
import requests
#抓取源代码
fs = open('source1.txt','wb')
url = "http://image.so.com/"
ctext = requests.get(url)
fs.write(ctext.content)
fs.close()
fs = open('source1.txt','r')
html = fs.read()
fs.close()
#匹配图片网址
pic_url = re.findall('src="(.*?)"',html,re.S)
i=0
for each in pic_url:
if re.findall('jpg',each):
print 'now downloading:'+each
pic = requests.get(each)
fp = open('pic\\'+str(i)+'.jpg','wb')
fp.write(pic.content)
fp.close()
i+=1
if re.findall('png',each):
print 'now downloading:'+each
pic = requests.get(each)
fp = open('pic\\'+str(i)+'.png','wb')
fp.write(pic.content)
fp.close()
i+=1