Python爬虫1
来源:互联网 发布:电脑刺绣软件 编辑:程序博客网 时间:2024/05/21 09:42
正则表达式的各种用法
#-*-coding:utf8-*-#导入re库文件import re# from re import findall,search,Ssecret_code = 'hadkfalifexxIxxfasdjifja134xxlovexx23345sdfxxyouxx8dfse'#.的使用举例# a = 'xy123'# b = re.findall('x...',a)# print b#*的使用举例# a = 'xyxy123'# b = re.findall('x*',a)# print b#?的使用举例# a = 'xy123'# b = re.findall('x?',a)# print b'''上面的内容全部都是只需要了解即可,需要掌握的只有下面这一种组合方式(.*?)'''# #.*的使用举例# b = re.findall('xx.*xx',secret_code)# print b# # #.*?的使用举例# c = re.findall('xx.*?xx',secret_code)# print c#### #使用括号与不使用括号的差别# d = re.findall('xx(.*?)xx',secret_code)# print d# for each in d:# print each#re.S使.包括换行符\n,让.除了匹配任意符还包括换行符"\n"# s = '''sdfxxhello# xxfsdfxxworldxxasdf'''## d = re.findall('xx(.*?)xx',s,re.S)# print d#对比findall与search的区别# s2 = 'asdfxxIxx123xxlovexxdfd'# # f = re.search('xx(.*?)xx123xx(.*?)xx',s2).group(2)# # print f# f2 = re.findall('xx(.*?)xx123xx(.*?)xx',s2)# print f2[0][1]#sub的使用举例# s = '123rrrrr123'# output = re.sub('123(.*?)123','123%d123'%789,s)# print output#演示不同的导入方法,推荐使用"import re"这种方式,代码中显示re.findall(),re.S# info = findall('xx(.*?)xx',secret_code,S)# for each in info:# print each#不要使用compile# pattern = 'xx(.*?)xx'# new_pattern = re.compile(pattern,re.S)# output = re.findall(new_pattern,secret_code)# print output#匹配数字a = 'asdfasf1234567fasd555fas'b = re.findall('(\d+)',a)print b
0 0
- python 爬虫(1)
- Python爬虫1
- [Python]网络爬虫1
- Python爬虫系列:1
- Python 爬虫学习1
- Python爬虫----1
- python爬虫1
- python爬虫1
- python 爬虫(1)
- Python爬虫基础-1
- python--爬虫1
- Python爬虫学习1
- python爬虫练习1
- Python 爬虫学习1
- python爬虫1
- Python爬虫(1)
- Python爬虫例子1
- python爬虫练习1
- hdu1312
- hdu 5374 Tetris(模拟俄罗斯方块)
- jQuery 获取当前节点的html包含当前节点的方法
- 面向对象,集合篇(1)
- Android 学习之Fragment生命周期
- Python爬虫1
- c/c++里的 堆区 栈区 静态区 文字常量区 程序代码区
- scala-08Scala主构造器、私有构造器、构造器重载实战详解
- poj 2349 Arctic Network
- 矩阵链乘
- 配置自己的OpenGL库,glew、freeglut库编译,库冲突解决(附OpenGL Demo程序)
- 动态加载
- 素数打表法。
- HDU 1014 Uniform Generator (水题_格式控制)