使用Python正则表达式提取HTML表格数据
{"title":"使用Python正则表达式提取HTML表格数据","description":"本文介绍如何使用Python的re模块提取HTML表格数据中包含在
python\nimport re\n\ndata = '<td>faefhieahfioafi</td><td>fhaiwehfoiehfiafhiofniafneawif<img>fafeaf</img></td>'\npattern = r'<td>(.*?)</td>'\nresult = re.findall(pattern, data)\n\nprint(result)\n\n\n输出结果:\n\n\n['faefhieahfioafi', 'fhaiwehfoiehfiafhiofniafneawif<img>fafeaf</img>']\n\n\n在正则表达式中,<td>和</td>分别匹配<td>和</td>标签,而(.*?)匹配任意字符(非贪婪模式),.*表示任意字符,?表示非贪婪匹配,()用于捕获匹配的内容。re模块的findall函数会返回所有匹配的结果,最后将其打印出来。"}
原文地址: https://www.cveoy.top/t/topic/p40o 著作权归作者所有。请勿转载和采集!