用python的re提取出下面数据中包含在tdtd的数据并放列表中tdfaefhieahfioafitdtdfhaiwehfoiehfiafhiofniafneawifimgfafeafimgtd
你可以使用re模块的findall函数来提取出符合条件的数据,并将其放入列表中。下面是一个示例代码:
import re
data = '<td>faefhieahfioafi</td><td>fhaiwehfoiehfiafhiofniafneawif<img>fafeaf</img></td>'
pattern = r'<td>(.*?)</td>'
result = re.findall(pattern, data)
print(result)
输出结果:
['faefhieahfioafi', 'fhaiwehfoiehfiafhiofniafneawif<img>fafeaf</img>']
在正则表达式中,<td>和</td>分别匹配<td>和</td>标签,而(.*?)匹配任意字符(非贪婪模式),.*表示任意字符,?表示非贪婪匹配,()用于捕获匹配的内容。re模块的findall函数会返回所有匹配的结果,最后将其打印出来。
原文地址: https://www.cveoy.top/t/topic/im0f 著作权归作者所有。请勿转载和采集!