我一直在尋找一種方法來剝離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