Python re 模块分割 img 标签
您可以使用Python的re模块来将每个<img>标签分开。下面是一个示例代码:
import re
text = "<img faefiafadflk nihao style='fafeea'><img faeffaaaaaa fnaiehf style='faefa'><img faeffafewf ffefaiehf style='faffefa'>"
# 使用正则表达式匹配<img>标签
pattern = r"<img[^>]*>"
imgs = re.findall(pattern, text)
print(imgs)
输出:
['<img faefiafadflk nihao style='fafeea'>', '<img faeffaaaaaa fnaiehf style='faefa'>', '<img faeffafewf ffefaiehf style='faffefa'>']
这样,每个<img>标签都被分开并存储在列表imgs中。
原文地址: https://www.cveoy.top/t/topic/p40J 著作权归作者所有。请勿转载和采集!