代码如下:
# -*- coding:utf-8 -*-
import httplib
import urllib
import string
import re
def getContent(): #从网站中获取所有内容
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') #编码根据实际情况酌情处理
return data1
def getImageUrl(data): #将获取到img链接写到sour.txt文件中国
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('
')
sour.close()
def downImage(): #根据testsour.txt里面的url自动下载图片
tt = 0 #name
sour = open('testsour.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()
Modoer 是一款以本地分享,多功能的点评网站管理系统。采用 PHP+MYSQL 开发设计,开放全部源代码。因具有非凡的访问速度和卓越的负载能力而深受国内外朋友的喜爱,不局限于商铺类点评,真正实现了多类型的点评,可以让您的网站点评任何事与物,同时增加产品模块,也更好的网站产品在网站上展示。Modoer点评系统 2.5 Build 20110710更新列表1.同步 旗舰版系统框架2.增加 限制图片
2
content = getContent()
getImageUrl(content)
downImage()
python怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号