使用python rgex从html中删除不需要的标签

时间:2018-03-11 15:06:00

标签: html regex python-3.x

我是python的初学者。我需要你们的快速帮助。这是我的情景。我在一个文件夹中有多个html文件。我需要从那些html文件中删除一些不需要的标签。你能给出一个最佳和优化的方法来删除我所有文件中的标签(文件范围大约500)。我使用正则表达式删除这些标签。

这是我的示例html:

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="willing pop" content="Sent for Review" />
<meta name="generator" content="Adobe RoboHelp 2015" />
<title>System Access</title>
<link rel="StyleSheet" href="..\..\..\default.css" type="text/css" />
</head>

<body>no text found</body>

在上面的html我想要&#34;没有发现文字&#34;单独

我的尝试但它不起作用(python 3):

import re
with open(r"E:\python\testfiles\sample.html")as opn:
    k=opn.read()
    v=re.sub(r"<\?xml.* .*  *.>","",k,re.I|re.M)
    print(v)

提前感谢您的帮助。

0 个答案:

没有答案
相关问题