Python 获取sina首页所有jpg图片
2014-09-06 22:00
393 查看
#!/usr/bin/python
#encoding:utf8
import re #导入正则库
import urllib
def getHtmlSource( url ): #获取网页源代码
pageHandle = urllib.urlopen( url )
htmlSource = pageHandle.read()
return htmlSource
def getImgHref( source ): #获取所有的链接
reg = r'src="(.*?\.jpg)" width'
imageRe = re.compile(reg)
imageList = re.findall(imageRe, source)
return imageList
def downLoad(imageList): #进行下载
count = 0
for imageUrl in imageList:
print "download ",imageUrl," now!"
urllib.urlretrieve(imageUrl, "%s.jpg" % count) #下载 并更改名称
count += 1
source = getHtmlSource("http://www.sina.com.cn/")
imageList = getImgHref( source )
downLoad(imageList)
#encoding:utf8
import re #导入正则库
import urllib
def getHtmlSource( url ): #获取网页源代码
pageHandle = urllib.urlopen( url )
htmlSource = pageHandle.read()
return htmlSource
def getImgHref( source ): #获取所有的链接
reg = r'src="(.*?\.jpg)" width'
imageRe = re.compile(reg)
imageList = re.findall(imageRe, source)
return imageList
def downLoad(imageList): #进行下载
count = 0
for imageUrl in imageList:
print "download ",imageUrl," now!"
urllib.urlretrieve(imageUrl, "%s.jpg" % count) #下载 并更改名称
count += 1
source = getHtmlSource("http://www.sina.com.cn/")
imageList = getImgHref( source )
downLoad(imageList)
相关文章推荐
- python获取某网址下所有图片
- python获取网页中所有图片并筛选指定分辨率的方法
- 使用python查询某目录下所有‘jpg’结尾的图片文件
- 使用Python获取所有非偶数尺寸图片资源信息
- python爬虫三:获取一个网易用户的所有图片(selenium+phantomjs)
- Python Requests爬虫——获取一个收藏夹下所有答案的图片
- 【Android】获取所有jpg和png图片
- python获取网页中所有图片并筛选指定分辨率
- 一条JavaScript语句获取当前网页所有图片的url
- 用javaScript获取文件,jpg图片大小
- 用javaScript获取文件,jpg图片大小
- Python获取APNIC地址库的所有IP地址Whois信息
- sina首页广告效果-JavaScript写让图片/一句话只显示3秒
- IE浏览器不显示所有jpg图片
- PDF首页转为图片,获取PDF页数
- 教你获取图片文件夹中所有图片的绝对路径列表
- python获取所有链接保存到数据表并依次打开
- 使用Python正则表达式从文章中取出所有图片路径
- Python recipe(15):获取类的所有成员
- 正则表达式获取网页中所有图片的路径