Python正则表达式总结
search(pattern,string,flags=0):在一个字符串中查找匹配
finddall(pattern,string,flags=0):找到匹配,返回所有匹配部分的列表
sub(pattern,repl,string,count=0,flags=0):将字符串中匹配正则表达式的部分替换为其他值
split(pattern,string,maxsplit=0,flags=0):根据匹配分割字符串, 返回分割字符串组成的列表
import urllibimport rereq = urllib.urlopen('http://www.imooc.com/course/list')buf = req.read()listurl = re.findall(r'http:.+.jpg', buf)print listurli = 0for url in listurl: f = open(str(i) + '.jpg', 'w') req = urllib.urlopen(url) buf = req.read() f.write(buf) i += 1
文章推荐
-
python 字典(dict)按键和值排序
下面小编就为大家带来一篇python 字典(dict)按键和值排序。小编觉得挺不错的,现在就分享给大家,也给大家做个参考...
Python
4分钟前 1 -
python中scipy.misc.logsumexp函数的运用
下面小编就为大家带来一篇浅谈python中scipy.misc.logsumexp函数的运用场景。小编觉得挺不错的,现在...
Python
5分钟前 1 -
python为什么不需要三目运算符和switch
下面小编就为大家带来一篇浅谈python为什么不需要三目运算符和switch。小编觉得挺不错的,现在就分享给大家,也给大...
Python
7分钟前 1 -
python运行时间的方法
这篇文章主要为大家详细介绍了python运行时间的几种方法,分析每一种运行时间方法的利弊,感兴趣的小伙伴们可以参考一下最...
Python
8分钟前 1 -
Windows安装Virtualenv来创建独立Python环境
有时我们的程序中需要调用不同版本的python包和模块,那么借助virtualenv的虚拟环境就可以帮助我们隔离使用,接...
Python
15分钟前 1
最新文章
- python 字典(dict)按键和值排序 4分钟前
- python中scipy.misc.logsumexp函数的运用 5分钟前
- python为什么不需要三目运算符和switch 7分钟前
- python运行时间的方法 8分钟前
- Windows安装Virtualenv来创建独立Python环境 15分钟前
- python实现多线程的方式 24分钟前
- python实现简单购物商城 25分钟前
- python字符串的常用操作方法 26分钟前
- python用户登录系统 26分钟前
- python中list列表高级函数 30分钟前