html 转 mht

html 转 mht,第1张

很简单,不需要软件也可以。

您可以用浏览器打开html文件,然后使用“文件”-“另存为”,在保存类型中选择相应项目即可。注意要是保存网页全部,会多处一个文件夹存放图片等文件,mht本来就是这样的 。

如果只是几个文件可以用ie打开hrml网页文件,在浏览器内地址栏输入:

JavaScript:document.write(document.body.innerText.replace(/<.*?>/g,""))

就可以只显示文本了。

但是我个人觉得你是想将下载的网页小说、资料等转换为txt的纯文字方便浏览吧。

这个文件是不是很多?那么就需要批量性的转换工具。

留下一个邮箱吧,我将软件发给你,可以大批量转换html为txt文档,还可以将多个文件合并为一个。

public boolean compile() {

if (strWeb == null || strText == null || strFileName == null || strEncoding == null)

return false

NodeList nodes = new NodeList()

try {

Parser parser = createParser(strText)

parser.setEncoding(strEncoding)

nodes = parser.parse(null)

} catch (ParserException e)

{

e.printStackTrace()

}

try {

createMhtArchive(strText)

} catch (Exception e) {

e.printStackTrace()

return false

}

return true

}

private Parser createParser(String inputHTML) {

Lexer mLexer = new Lexer(new Page(inputHTML))

return new Parser(mLexer, new DefaultParserFeedback(DefaultParserFeedback.QUIET))

}

private void createMhtArchive(String content) throws Exception {

MimeMultipart mp = new MimeMultipart("related")

Properties props = new Properties()

props.put("mail.smtp.host", smtp)

Session session = Session.getDefaultInstance(props, null)

MimeMessage msg = new MimeMessage(session)

msg.setHeader("X-Mailer", "Code Manager .SWT")

if (from != null) {

msg.setFrom(new InternetAddress(from))

}

if (subject != null) {

msg.setSubject(subject)

}

if (to != null) {

InternetAddress[] toAddresses = getInetAddresses(to)

msg.setRecipients(Message.RecipientType.TO, toAddresses)

}

if (cc != null) {

InternetAddress[] ccAddresses = getInetAddresses(cc)

msg.setRecipients(Message.RecipientType.CC, ccAddresses)

}

if (bcc != null) {

InternetAddress[] bccAddresses = getInetAddresses(bcc)

msg.setRecipients(Message.RecipientType.BCC, bccAddresses)

}

MimeBodyPart bp = new MimeBodyPart()

bp.setText(content, strEncoding)

bp.addHeader("Content-Type", "text/htmlcharset=" + strEncoding)

bp.addHeader("Content-Location", strWeb.toString())

mp.addBodyPart(bp)

msg.setContent

msg.writeTo(new FileOutputStream(strFileName))

System.out.print("444444444444444444444444444444444444")

}

private InternetAddress[] getInetAddresses(String emails) throws Exception {

ArrayList list = new ArrayList()

StringTokenizer tok = new StringTokenizer(emails, ",")

while (tok.hasMoreTokens()) {

list.add(tok.nextToken())

}

int count = list.size()

InternetAddress[] addresses = new InternetAddress[count]

for (int i = 0i <counti++) {

addresses[i] = new InternetAddress(list.get .toString())

}

return addresses

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/6301781.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-20
下一篇 2023-03-20

发表评论

登录后才能评论

评论列表(0条)

保存