正则表达式爬虫1
来源:互联网 发布:360医药软件 编辑:程序博客网 时间:2024/05/17 22:41
正则表达式小例子
import reli='hellonihaohello'a=re.search(r'\Ahello',li)print a.group()b=re.search(r'hello\Z',li)print b.group()li='i have a dream'c=re.search(r'\bhave\b',li)print c.group() content = 'i have a 34332589@qq.com dream one day ... 280000089@qq.com money neau'data=re.findall(r'\d{6,11}@qq\.com',content)print data
使用正则表达式爬取糗事百科图片
"""通过正则表达式,下载糗事百科图片"""import requestsimport re#设置下载网页的页面urlurl='https://www.qiushibaike.com/imgrank/'#设置请求头数据headers={ 'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0'}#发送请求response=requests.get(url,headers=headers)#解析数据html=response.content.decode('utf8')#print html# with io.open('d:/python/pachong/jiandan.txt','w',encoding='utf8') as f:# f.write(html)#通过正则表达式获取我们需要的数据reStr='<img src="/{1,2}[^(static)](.*?)"'data=re.findall(reStr,html)#print datafor item in data: if not item.startswith("http:"): item="http://"+item print item response = requests.get(item) data=response.content nameList=item.split("/") imageName=nameList[len(nameList)-1] a=re.search('.*(jpg)$',imageName) if(a!=None): print imageName with io.open('d:/python/pachong/'+imageName,'wb') as f: f.write(data)
阅读全文
0 0
- 正则表达式爬虫1
- Python爬虫学习笔记(1)-正则表达式
- Python爬虫实践(六):正则表达式(1)
- 正则表达式,网页爬虫
- 爬虫 正则表达式
- Python爬虫 正则表达式
- 爬虫与正则表达式
- 网络爬虫-正则表达式
- Python爬虫-正则表达式
- python爬虫-正则表达式
- 正则表达式爬虫实例
- 正则表达式—网页爬虫
- 正则表达式练习,网络爬虫
- Python爬虫之正则表达式
- (正则表达式)邮件地址爬虫
- python爬虫之正则表达式
- python爬虫和正则表达式
- OC爬虫 -- 结合正则表达式
- ubuntu如何访问windows共享文件夹
- 数据库SQL开发规范
- 如何粗鲁地破坏一个单例模式
- Spark2.0特征提取、转换、选择之一:数据规范化,String-Index、离散-连续特征相互转换
- 我做运营那些年,如何找到用户并留住用户?
- 正则表达式爬虫1
- 设计模式(二十九)------23种设计模式(21):代理模式
- 人脸识别数据集fetch_olivetti_faces()导入失败
- MYSQL问题
- 99乘法表
- mac环境变量配置
- Python问题分析:AttributeError: module 'sys' has no attribute 'setdefaultencoding'
- 产品微操的艺术:提高核心指标的5个需求原理(1~5完)
- 新产品孕育记:PM如何把一款产品从0带到1