欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python在多玩圖片上下載妹子圖的實(shí)現(xiàn)代碼

 更新時(shí)間:2013年08月13日 12:40:06   作者:  
學(xué)python的第二天,想寫(xiě)個(gè)東西出來(lái)玩玩,于是就寫(xiě)了這個(gè),供那些才學(xué)一天的參考參考也行

復(fù)制代碼 代碼如下:

# -*- coding:utf-8 -*-
import httplib
import urllib
import string
import re
def getContent():                   #從網(wǎng)站中獲取所有內(nèi)容
 conn = httplib.HTTPConnection("tu.duowan.com")
 conn.request("GET", "/m/meinv/index.html")
 r = conn.getresponse()
 print r.status, r.reason
 data1 = r.read()#.decode('utf-8') #編碼根據(jù)實(shí)際情況酌情處理
 return data1

def getImageUrl(data):            #將獲取到img鏈接寫(xiě)到sour.txt文件中國(guó)
 sour = open("test\\sour.txt", 'w')
 pplen = len("http://s1.dwstatic.com/group1/M00/37/2A/e2c30e89184ea942a4be9c1f7ba217a5.jpg")
 for i in range(len(data) - 3):
  if data[i] == 'i' and data[i + 1] == 'm' and data[i + 2] == 'g':
   for j in xrange(i + 9, i + 9 + pplen):
    sour.write(data[j])
   sour.write('\n')
 sour.close()

 


def downImage():               #根據(jù)test\\sour.txt里面的url自動(dòng)下載圖片
 tt = 0    #name
 sour = open('test\\sour.txt')
 while 1:
  line = sour.readline()
  if line:
   Len = len(line)
   #print Len
   if line[Len - 2] == 'g' and line[Len - 3] == 'p' and line[Len - 4] == 'j':
    path = line
    data = urllib.urlopen(line).read()
    f = open('test\\' + str(tt) + '.jpg', 'wb')
    f.write(data)
    f.close()
    tt = tt + 1
  else:
   break
 sour.close()

content = getContent()
getImageUrl(content)
downImage()

相關(guān)文章

最新評(píng)論