要查找包含特定字符串的href,可以使用以下正则表达式:

import re

text = 'href="https://v.qq.com/x/cover/mzc00200vmhuur7/i3505rf8da9.html?start=243&cut_vid=v0045ivl226&scene_id=3"'

pattern = r'href="(.*https://v.qq.com/x/cover/.*?)"'

match = re.search(pattern, text)

if match:
    print(match.group(1))

输出:

https://v.qq.com/x/cover/mzc00200vmhuur7/i3505rf8da9.html?start=243&cut_vid=v0045ivl226&scene_id=3

该正则表达式的含义是:匹配以href="开头,后面包含https://v.qq.com/x/cover/的字符串,直到遇到下一个"为止。.*?表示非贪婪匹配,匹配到最短的字符串。使用re.search()函数可以在文本中搜索匹配的内容,并使用group(1)获取第一个捕获组的内容。

想要通过正则查找到href开头的且其中包含有httpsvqqcomxcover的href例如这种href=httpsvqqcomxcovermzc00200vmhuur7i3505rf8da9htmlstart=243&cut_vid=v0045ivl226&scene_id=3

原文地址: https://www.cveoy.top/t/topic/jd47 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录