正则表达式实例

Posted zhaobobo10

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了正则表达式实例相关的知识,希望对你有一定的参考价值。

import requests
import re
url=‘https://movie.douban.com/cinema/nowplaying/beijing/‘#豆瓣电影网
resp=requests.get(url)
text=resp.text#返回内容
guize=‘<img src="(.*?)" alt="(.*?)".*?>(\d.*?)<‘#提取电影封面/电影名/评分,小括号内的代表提取内容,提取多个时都保存在一个元祖里面
photo=re.findall(guize,text,re.S)#参数1是规则,2是要匹配的内容,3是换行也匹配
for i in photo:
print(i)
# ‘<img src="https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2568261402.webp" alt="中国机长" rel="nofollow" class="">‘

以上是关于正则表达式实例的主要内容,如果未能解决你的问题,请参考以下文章

正则表达式表单验证实例代码详解

JS正则表达式详解

正则表达式

正则表达式高级技巧及实例详解

常见python正则用法实例

常用的操作正则表达式的方法+正则表达式基本元字符使用实例