使用html2text轻松制作txt格式的手机电子书

Totem,mplayer,sopcast,realplayer,bmp
回复
头像
yangjinchao
帖子: 119
注册时间: 2006-04-18 21:08
联系:

使用html2text轻松制作txt格式的手机电子书

#1

帖子 yangjinchao » 2009-10-05 21:50

闲来无事。喜欢在手机上看看电子书。我喜欢在百度百科上面将一些百科知识下载下来的网页转换成txt格式的手机电子书来看。一来增长知识,二来打发一些时间。有些朋友可能和我有一样的想法,
这个在windows上软件是一大把,很易用的。经过一些时间的摸索现将经验写下来,以节省有这个需要的朋友的时间。
我下载是用firefox下的扩展downthemall来批量下载的,这个我就不说了。

下面说下html2text的使用说明

代码: 全选

This is html2text, version 1.3.2a



Usage:

  html2text -help

  html2text -version

  html2text [ -unparse | -check ] [ -debug-scanner ] [ -debug-parser ] \

     [ -rcfile <file> ] [ -style ( compact | pretty ) ] [ -width <w> ] \

     [ -o <file> ] [ -nobs ] [ -ascii ] [ <input-url> ] ...

Formats HTML document(s) read from <input-url> or STDIN and generates ASCII

text.

  -help          Print this text and exit
   显示本页文本并退出
  -version       Print program version and copyright notice

  -unparse       Generate HTML instead of ASCII output
 
  -check         Do syntax checking only
    做语法检查
  -debug-scanner Report parsed tokens on STDERR (debugging)

  -debug-parser  Report parser activity on STDERR (debugging)

  -rcfile <file> Read <file> instead of "$HOME/.html2textrc"

  -style compact Create a "compact" output format (default)

  -style pretty  Insert some vertical space for nicer output

  -width <w>     Optimize for screen widths other than 79

  -o <file>      Redirect output into <file>
 将输入重新输出至 <file>
  -nobs          Do not use backspaces for boldface and underlining

		    这个选项要用着。不然的话转换后的文件 里会有很多没用的符号
			
  -ascii         Use plain ASCII for output instead of ISO-8859-1
先是转换了一个试一下
用了如下命令

假若要1.html 转换为2.txt

代码: 全选

html2text -o 2.txt -nobs 1.html
转换的很成功。并且html转换成txt后编码没变。


虽然转化单个文件是功了。但是要批量转化怎么办
这里shell脚本的威力显现出来了
新建一个文件文件 就叫html2text.sh吧,里面的内容如下。不用详细解释这个脚本了。

代码: 全选

#!/bin/bash

ls *.html |while read i

do html2text -o $i.txt -nobs $i

done

然后保存后加上可执行

代码: 全选

chmod +x html2text.sh
后放入要转换的html的目录下。执行这个脚本。一会功夫20多个文件转换完成了。是不是很轻松啊 :em09
附件
Screenshot-html - 文件浏览器.png
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
欢迎光临我的网站 免费软件中国
linux视频教程,免费软件介绍使用
http://freesoftcn.com
头像
HuaChong
帖子: 493
注册时间: 2006-09-12 17:10

Re: 使用html2text轻松制作txt格式的手机电子书

#2

帖子 HuaChong » 2010-06-06 18:24

楼主的工具怎么没有上来
头像
xxzc
帖子: 151
注册时间: 2009-01-26 17:45
联系:

Re: 使用html2text轻松制作txt格式的手机电子书

#3

帖子 xxzc » 2010-08-15 17:49

转换成功 :em02
wangtwo
帖子: 73
注册时间: 2007-05-07 9:42

Re: 使用html2text轻松制作txt格式的手机电子书

#4

帖子 wangtwo » 2010-09-28 22:23

RESTRICTIONS
Debian version of html2text have no http support. Use html2text through
pipes with curl or wget instead. See README.Debian for more informa‐
tion.

html2text was written to convert HTML 3.2 documents. When using it with
HTML 4 or even XHTML 1 documents, some constructs present only in these
HTML versions might not be rendered.
回复