python爬虫(五)图片下载爬虫
2017-07-01 17:30
197 查看
在网页的源代码中,图片的信息在<img> 标签中 其中<img src=>中表明图片所在地址,<img class=>表明图片类型,如表情图片,正常图片,还是广告图片
#--*coding:utf-8
import urllib
import re
#正则表达式
def get_content(url):
"""获得文档"""
html = urllib.urlopen(url)
content = html.read()
html.close()
return content
def get_images(info):
"""
<img class ="BDE_Image" src="http://" pic_ext="jpeg" changedsize="true" width="50" height="373">
"""
regex = r'class="BDE_Image" src="(.+?\.jpg)"'
pat = re.compile(regex)
i = 0
images_code = re.findall(pat,info)
#print len(images_code)
for image_url in images_code:
print image_url
urllib.urlretrieve(image_url,'%s.jpg'%i)
i +=1
url = "https://tieba.baidu.com/p/2772656630"
info = get_content(url)
print get_images(info)
#--*coding:utf-8
import urllib
import re
#正则表达式
def get_content(url):
"""获得文档"""
html = urllib.urlopen(url)
content = html.read()
html.close()
return content
def get_images(info):
"""
<img class ="BDE_Image" src="http://" pic_ext="jpeg" changedsize="true" width="50" height="373">
"""
regex = r'class="BDE_Image" src="(.+?\.jpg)"'
pat = re.compile(regex)
i = 0
images_code = re.findall(pat,info)
#print len(images_code)
for image_url in images_code:
print image_url
urllib.urlretrieve(image_url,'%s.jpg'%i)
i +=1
url = "https://tieba.baidu.com/p/2772656630"
info = get_content(url)
print get_images(info)
相关文章推荐
- python 百度贴吧爬虫(下载图片)
- 我的第一个python爬虫程序(从百度贴吧自动下载图片)
- 每天一篇python:简单爬虫下载图片篇
- Python简单知乎爬虫--爬取页面的图片并下载到本地
- Python 爬虫5——爬取并下载网页指定规格的图片
- Python 爬虫学习 网页图片下载
- python爬虫 分页获取图片并下载
- Python爬虫下载网站上的图片到本地
- Python 3 爬虫之批量下载字帖图片
- Python3 爬虫下载指定页面图片
- python爬虫图片下载
- python实现爬虫下载美女图片
- [python][爬虫]从网页中下载图片
- python爬虫(1)下载任意网页图片
- python中使用网络爬虫下载图片
- python 爬虫学习<将某一页的所有图片下载下来>
- python实现爬虫下载美女图片
- python实现爬虫下载美女图片
- Python 爬虫5——爬取并下载网页指定规格的图片
- python爬虫框架scrapy学习图片下载