# -*-coding:utf-8-*—
'''
题目描述:
用 Python 写一个爬图片的程序,爬 这个链接里的日本妹子图片 :-)
地址:
http://tieba.baidu.com/p/2166231880 思路:
用正则表达式匹配图片链接,然后进行下载 '''
'''
import re
import requests def main():
url = 'http://tieba.baidu.com/p/2166231880'
response = requests.get(url)
html = response.text
match = re.compile('img .*?src=\"(.*?)\"')
for i in match.findall(html):
if 'imgsrc' in i :
print i if __name__ == '__main__':
main()
''' import urllib2
import re
from os.path import basename
from urlparse import urlsplit url = "http://tieba.baidu.com/p/2166231880"
def getPage(url):
url=url+"?see_lz=1"
urlContent = urllib2.urlopen(url).read()
page='<span class="red">(.*?)</span>'
thePage=re.findall(page,urlContent)
return int(thePage[0])
def downImg(url):
urlContent = urllib2.urlopen(url).read()
spans='<cc>(.*?)</cc>'
ss=re.findall(spans,urlContent)
obImgs=','.join(ss)
imgUrls = re.findall('img .*?src="(.*?)"', obImgs)
for imgUrl in imgUrls:
print imgUrl
'''
try:
imgData = urllib2.urlopen(imgUrl).read()
fileName = basename(urlsplit(imgUrl)[2])
output = open(fileName,'wb')
output.write(imgData)
output.close()
except:
print "Er.."
'''
def downLoad(url):
numb=getPage(url)
cont=0
print "There are "+str(numb)+" pages."
while cont<numb:
cont+=1
print "Downloading "+url+"?see_lz=1&pn="+str(cont)+"..."
downImg(url+"?see_lz=1&pn="+str(cont))
print 'Completed!' downImg(url)

python练习册 每天一个小程序 第0013题的更多相关文章

  1. python练习册 每天一个小程序 第0001题

    1 # -*-coding:utf-8-*- 2 __author__ = 'Deen' 3 ''' 4 题目描述: 5 做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生 ...

  2. python练习册 每天一个小程序 第0007题

    1 # -*-coding:utf-8-*- 2 __author__ = 'Deen' 3 ''' 4 题目描述: 5 有个目录,里面是你自己写过的程序,统计一下你写过多少行代码.包括空行和注释,但 ...

  3. python练习册 每天一个小程序 第0000题

    PIL库学习链接:http://blog.csdn.net/column/details/pythonpil.html?&page=1 1 #-*-coding:utf-8-*- 2 __au ...

  4. python练习册 每天一个小程序 第0010题

    # -*-coding:utf-8-*- ''' 题目描述: 使用 Python 生成类似于下图中的字母验证码图片 思路: 运用PIL库加random 随机字母进行生成 ''' import rand ...

  5. python练习册 每天一个小程序 第0009题

    1 ''' 2 题目描述: 3 找出一个html文件中所有的url 4 5 思路 : 6 利用正则表达式进行匹配 7 8 ''' 9 10 11 import re 12 13 14 with ope ...

  6. python练习册 每天一个小程序 第0008题

    1 # -*-coding:utf-8-*- 2 __author__ = 'Deen' 3 ''' 4 题目描述: 5 一个HTML文件,找出里面的正文. 6 7 思路: 8 利用Beautiful ...

  7. python练习册 每天一个小程序 第0006题

    1 # -*-coding:utf-8-*- 2 __author__ = 'Deen' 3 ''' 4 题目描述: 5 你有一个目录,放了你一个月的日记,都是 txt,为了避免分词的问题,假设内容都 ...

  8. python练习册 每天一个小程序 第0005题

    1 # -*-coding:utf-8-*- 2 __author__ = 'Deen' 3 ''' 4 题目说明: 你有一个目录,装了很多照片,把它们的尺寸变成都不大于 iPhone5 分辨率的大小 ...

  9. python练习册 每天一个小程序 第0012题

    # -*-coding:utf-8-*- def test(content): text = content flag = 0 with open('filtered_words.txt') as f ...

随机推荐

  1. mysql查询的时候没有加order by时的默认排序问题

    有时候我们执行MySQL查询的时候,查询语句没有加order by,但是发现结果总是已经按照id排序好了的,难道MySQL就是为了好看给我们排序 如上图数据,是我查询了语句 SELECT * from ...

  2. Solution -「洛谷 P5325」Min_25 筛

    \(\mathcal{Description}\)   Link.   对于积性函数 \(f(x)\),有 \(f(p^k)=p^k(p^k-1)~(p\in\mathbb P,k\in\mathbb ...

  3. FastDFS安装和简介详细总结

    1.fastDFS简介 1 FastDFS是用c语言编写的一款开源的分布式文件系统. 2 FastDFS为互联网量身定制,充分考虑了冗余备份.负载均衡.线性扩容等机制,并注重高可用.高性能等指标, 3 ...

  4. 【基础篇】js对本地文件增删改查--改

    前置条件: 1. 本地有安装node,点击传送门 项目目录: 1. msg.json内容 { "data": [ { "id": 1, "name&q ...

  5. RFC2889错误帧过滤测试----网络测试仪实操

    一.简介 RFC 2889为LAN交换设备的基准测试提供了方法学,它将RFC 2544中为网络互联设备基准测试所定义的方法学扩展到了交换设备,提供了交换机转发性能(Forwarding Perform ...

  6. 学习Spring5必知必会(6)~Spring DAO

    一.Spring 对持久层技术的支持 Spring DAO 1.模板类: 2.基类: 二.spring JDBC [JDBCTemplate 模板类] 1.案例:使用jdbc 完成crud操作 (1) ...

  7. C#中的泛型 / 泛型类 / 数组、ArrayList和List三者的区别

    在C#中数组,ArrayList,List都能够存储一组对象,那么这三者到底有什么样的区别呢. 数组 数组在C#中最早出现的.在内存中是连续存储的,所以它的索引速度非常快,而且赋值与修改元素也很简单. ...

  8. MySQL创建表、更改表和删除表

    1.创建表 mysql> create table t_address( -> id int primary key auto_increment, // 设置id为主键,自动增值 -&g ...

  9. Iptables 防火墙常用配置

    转至:https://blog.csdn.net/lswzw/article/details/87971259 Iptables 防火墙常用配置 概念 命令行模式 查看 & 命令 -n:直接显 ...

  10. journactl日志查看命令-渐入佳境

    --作者:飞翔的小胖猪 --创建时间:2021年2月27日 内容 journalctl是systemd统一管理所有unit(服务)的启动日志.可以通过journalctl一个命令查看所有日志. 所有用 ...