python爬虫之正则表达式
来源:互联网 发布:ubuntu 阿里源 gpg 编辑:程序博客网 时间:2024/05/19 03:17
search函数
import re #re库pattern=re.compile(r'worlda') #compile编译生成可操作对象m=re.search(pattern,'hello world!') #search的结果有一些属性,其 #中group()返回[**如果查找成功,则返回匹配的段落**]。if m: print(m.group())
split函数
import repattern=re.compile(r'\d+') #\d+匹配数字print(re.split(pattern,'one1two2three3four4')) # 返回被分割几个字母段,包括空段=====输出['one', 'two', 'three', 'four', '']
findall函数
import repattern = re.compile(r'\d+')print(re.findall(pattern,'one1two2three3four4'))#找出所有的数字
finditer函数
import repattern=re.compile(r'\d+')for m in re.finditer(pattern,'one1two2three3four4'):#返回数字迭代器 print (m.group())
阅读全文
0 0
- Python爬虫之正则表达式
- python爬虫之正则表达式
- python爬虫之正则表达式
- python爬虫之正则表达式
- Python爬虫入门七之正则表达式
- Python爬虫入门七之正则表达式
- python爬虫之神器正则表达式
- Python爬虫入门七之正则表达式
- 把玩之python爬虫正则表达式
- Python爬虫入门七之正则表达式
- Python爬虫入门七之正则表达式
- Python爬虫入门七之正则表达式
- Python爬虫入门七之正则表达式
- Python爬虫入门七之正则表达式
- python爬虫之re正则表达式库
- Python爬虫入门七之正则表达式
- python爬虫之正则表达式基础
- Python爬虫入门一之正则表达式
- webservices
- Maven学习之入门二
- JZOJ 3754 【NOI2014】魔法森林
- [bzoj2301]problem b 莫比乌斯反演
- 第k大问题各类变种小结
- python爬虫之正则表达式
- 【模板】KMP字符串匹配
- 【ShawnZhang】这次什么都不带你看了—— 分隔符
- apache 下配置网站单一入口
- 操作系统(6)
- 给初学者的 RxJava2.0 教程 (八)
- xcode卡死乱象
- faster rcnn训练自己地数据时遇到地问题
- React Native 在原生项目中集成之坑点总结