我一直在寻找一种方法来剥离html文档中的所有内容,只留下html标签。有没有人知道这个方法?我有许多Perl模块的经验,并已彻底搜索此网站。使用Perl剥离除html标签以外的所有内容
我想将html作为字符串传递给我的perl脚本并删除除标记之外的所有内容。这里有一个例子:
传入:
<!doctype html>
<html>
<head>
<title>Example Domain</title>
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
body {
background-color: #f0f0f2;
margin: 0;
padding: 0;
font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
}
div {
width: 600px;
margin: 5em auto;
padding: 50px;
background-color: #fff;
border-radius: 1em;
}
a:link, a:visited {
color: #38488f;
text-decoration: none;
}
@media (max-width: 700px) {
body {
background-color: #fff;
}
div {
width: auto;
margin: 0 auto;
border-radius: 0;
padding: 1em;
}
}
</style>
</head>
<body>
<div>
website content ....
</div>
</body>
</html>
变为:
<html><head><title></title><meta><meta><meta><style></style></head><body><div><h1></h1> <p></p><p><a></a></p></div></body></html>
成为了什么?我讨厌它,当人们... – hjpotter92
修复,第一次处理在这个网站上的代码工具。 ;) – user2421267
你想要删除标签属性?如果是这样,你应该可以做一个类似于/?\w+? ?>/ – Robbert