簡單的python抓圖小腳本

# -*- coding: utf-8 -*-
import re
import os
import urllib
def getpic(keyword):
  y=1
  x=1
  if os.path.exists('/%s'%keyword) is False:
    os.mkdir('%s'%keyword)
  while True:
    html = urllib.urlopen('http://image.xxxxxx.com/search/index?tn=xxxximage&word=%s&pn=%s'%(keyword,y))
    html1 = html.read()
    htmlrule = re.findall('http://.+?\.jpg',html1)
    htmlrule1 = list(set(htmlrule))
    y=y+60
    for line in htmlrule1:
      urllib.urlretrieve(line,filename='%s/%s.jpg'%(keyword,x))
      a = os.stat('%s/%s.jpg'%(keyword,x))
      b = '%.2f'% (a[6]/1024.0)
      b1 = float(b)
      if b1 < 10:
          os.remove('%s/%s.jpg'%(keyword,x))
          continue
      else:
          x=x+1
keyword = raw_input('enter your keyword:')
getpic(keyword)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章