掌上百科 - PDAWIKI

 找回密码
 免费注册

QQ登录

只需一步,快速开始

查看: 4489|回复: 4

[教程] 制作Dictionary of Phrase and Fable, E. Cobham Brewer, 1894

[复制链接]

该用户从未签到

发表于 2013-11-14 08:24:13 | 显示全部楼层 |阅读模式
本帖最后由 Oeasy 于 2013-11-17 09:54 编辑 ) A+ ^6 Q  T! p6 K

9 @8 T" |- f$ ]3 c) b5 I& L" K2 v0 }3 k2 d) p% Y
一个简单得不能再简单的网页抓取然后制作mdx教程(20131114)
0 Z1 U4 n  j5 `" y! m5 `
3 b) k1 J) R0 N2 B使用软件) w1 f5 B% u  ~; S
0. 操作系统:Windows 7 旗舰版64位
& e' l8 h+ n) b3 m1 L' h, Y1. 抓取工具:wget,http://users.ugent.be/~bpuype/wget/http://baike.baidu.com/view/1312507.htm
5 c$ J2 D# {* q& p5 t! g2. 文本处理:EditPlus, UltraEdit, TextForever(http://www.comicer.com/stronghorse/software/index.htm#TextForever
% W8 u! }3 s" j& q: S
9 E) d+ t6 s' k! l7 F" p/ \目标词典
% Q  E! `9 c7 W5 K* v6 J/ aDictionary of Phrase and Fable,1894: http://www.infoplease.com/dictionary/brewers/ 这词典是公版的,而且网站没有设置抓取限制(至少目前看来没有设置),获取index也非常容易,故以此为例。  [1 B$ |5 k7 t: W9 b3 [! s8 ~
另:有个pdf http://pan.baidu.com/share/link?shareid=267207&uk=2063908536,版本不详,似乎是第17版的。' _, B4 E( v/ {9 e" x$ v7 w: e
: b! I: {: @; ]6 f" u2 T' n
操作步骤
6 H" N' J" y( D7 a$ l1. 获取index3 @$ ~+ ?4 E- A2 W# s$ |
观察http://www.infoplease.com/dictionary/brewers/,该网站本身可以browse整本词典,获取index非常容易。2 }7 o* U0 d6 h$ G1 S. b
新建一个txt,内容为
; z# p  Q) E. r- o7 L, m
http://www.infoplease.com/dictionary/brewers/index-a.html
: c' K- E: z4 Q1 Lhttp://www.infoplease.com/dictionary/brewers/index-b.html
9 V- v& d5 {, Q" S( O( W0 D6 ahttp://www.infoplease.com/dictionary/brewers/index-c.html
1 D3 R1 D, L4 M; l( ]' u* ~http://www.infoplease.com/dictionary/brewers/index-d.html' D# B4 n8 c" [' D& z% K
http://www.infoplease.com/dictionary/brewers/index-e.html
0 p) @9 X1 M/ a& }http://www.infoplease.com/dictionary/brewers/index-f.html+ M7 s+ @% A: K2 |% |/ p% t% w
http://www.infoplease.com/dictionary/brewers/index-g.html# }& g3 I; }# H+ [) ^# T
http://www.infoplease.com/dictionary/brewers/index-h.html
8 ?7 R% B* F( l" {http://www.infoplease.com/dictionary/brewers/index-i.html1 X" }  _: j) [
http://www.infoplease.com/dictionary/brewers/index-j.html
1 c! I' u1 W4 y$ j' F! }http://www.infoplease.com/dictionary/brewers/index-k.html
* d8 a* [0 \/ t/ \$ R$ p/ Whttp://www.infoplease.com/dictionary/brewers/index-l.html. t: O$ o* Y* \3 }: s' y! o6 \
http://www.infoplease.com/dictionary/brewers/index-m.html  v3 c" Y* X. m' ?
http://www.infoplease.com/dictionary/brewers/index-n.html( J6 f0 N& D+ w6 L, B
http://www.infoplease.com/dictionary/brewers/index-o.html
. ?# \. F1 y4 ^) Z( }& m4 yhttp://www.infoplease.com/dictionary/brewers/index-p.html1 s$ X" i" A& U5 H- v
http://www.infoplease.com/dictionary/brewers/index-q.html
. E0 u) J& K* l; thttp://www.infoplease.com/dictionary/brewers/index-r.html4 T) @' k3 s3 K6 t" i% e
http://www.infoplease.com/dictionary/brewers/index-s.html- H" {3 J+ O1 [' a$ U5 Z
http://www.infoplease.com/dictionary/brewers/index-t.html# W5 Q0 A+ ^: G& g
http://www.infoplease.com/dictionary/brewers/index-u.html/ n" q7 q8 N" B+ }$ w+ o$ }- m
http://www.infoplease.com/dictionary/brewers/index-v.html
3 e* ]& D& p: i) W  `  `http://www.infoplease.com/dictionary/brewers/index-w.html/ Q+ M* o; J; \8 E! E" d  b8 Y3 o
http://www.infoplease.com/dictionary/brewers/index-x.html
, g0 H- D* W* B8 |/ X. q/ h* xhttp://www.infoplease.com/dictionary/brewers/index-y.html1 M7 t. R. F" F+ U' n
http://www.infoplease.com/dictionary/brewers/index-z.html

/ P' k$ y1 Z4 D& N4 p这些地址都是观察上面网站而得,txt命名为download.txt。
/ U( j) v( P- `# @( z7 i+ S( d我把这个download.txt和wget.exe(如果你下载的wget是wget+版本号.exe,不妨重命名为wget.exe),这俩文件都放在D:\DOPF下。
2 I+ K# u& w- u& D) d
2 p/ e1 G. \/ \. R4 Z: Q. Scmd.exe->CD/D D:\DOPF->wget -i download.txt
& K5 ^, K7 ~& W- I7 H! {9 D$ K3 f# V6 g2 F& W6 U! {
很快,26个html文件就下下来了,对这26个html文件进行整理,得到( w  j3 T/ y- u, j
http://www.infoplease.com/dictionary/brewers/a.html
/ h( s$ S% s, @http://www.infoplease.com/dictionary/brewers/a1.html' U) U9 l8 K! p& c/ F
http://www.infoplease.com/dictionary/brewers/a-b.html- D* |6 E: t/ l- V+ v# z
http://www.infoplease.com/dictionary/brewers/a-b-c.html% d3 z# \4 A% ?7 j9 U3 v
http://www.infoplease.com/dictionary/brewers/a-b-c-book.html
$ F( [) D2 F+ w% j. n3 g- hhttp://www.infoplease.com/dictionary/brewers/a-b-c-process.html
- e( W1 H! h9 n  ahttp://www.infoplease.com/dictionary/brewers/a-e-i-o-u.html
6 [) x9 A( H0 V& N) W+ |0 khttp://www.infoplease.com/dictionary/brewers/a-u-c.html
* T* |: ?1 z, Nhttp://www.infoplease.com/dictionary/brewers/aaron.html# R# T5 x. H! ~! P- w8 m
http://www.infoplease.com/dictionary/brewers/ab.html: k% ?4 k8 a# u
http://www.infoplease.com/dictionary/brewers/aback.html
* R) i. g% Q+ G' A4 B5 e, ~0 mhttp://www.infoplease.com/dictionary/brewers/abacus.html
' S2 W1 X) n3 t& _$ L( ihttp://www.infoplease.com/dictionary/brewers/abaddon.html/ Z1 F7 Q: a" X' H
http://www.infoplease.com/dictionary/brewers/abambou.html0 [7 Q- L0 W8 q! X1 V- U
http://www.infoplease.com/dictionary/brewers/abandon.html$ }5 ]+ W( u# E: G
http://www.infoplease.com/dictio ... on-fait-larron.html/ [2 K9 A) W' Z! r
http://www.infoplease.com/dictionary/brewers/abaris.html* e0 w; b# }8 Q/ w
http://www.infoplease.com/dictionary/brewers/abate.html
% X2 i3 O  }. q- U! Q: ghttp://www.infoplease.com/dictionary/brewers/abaton.html8 X( `5 D8 d* p. A9 Q- |
http://www.infoplease.com/dictionary/brewers/abbassides.html
5 b- b5 s+ \; `9 ]7 g* Uhttp://www.infoplease.com/dictionary/brewers/abbey-laird.html' M5 q$ x0 g* `; H' \- j4 J9 p; k
http://www.infoplease.com/dictionary/brewers/abbey-lubber.html0 V/ |, h+ }% h! O8 ~9 G* P
……

+ Z" |; i% c$ V这样的一共16698个链接。, S. D- x1 f1 c4 \6 U
$ T* v# Y% ~, O2 G. n) O# H7 G
2. 抓取内容0 ?: f0 _; f- `8 S) L
同样的,wget -i download.txt7 n$ t6 D0 _  N' l- y, \/ u% Z, N
把上面那N个html都抓下来,然后就很简单了。+ }% r; E! P4 H$ F4 m
-2013年11月14日 16:35:47  ~# m5 z- v1 a5 {2 a, w
成功抓取了16695个html,漏了3个,懒得研究到底是哪3个了。
% m8 L7 Z% Q: {( d; f/ F; }8 a/ I7 p" \6 v% y) O
3. 文本提取
9 [4 X& e! I4 q& h, r; I1 Y观察可知,词典条目内容在第一个<h1>和<div class="source">之间9 q# O" h3 W* ?. a, H3 B
<h1>Charybdis</h1># ?3 l: l5 j" E; R7 y# L: |
# B! c% x. P$ f8 A  E( v
<p> [ch=k]. A whirlpool on the coast of Sicily. Scylla and
5 I$ s' w  ?" X* {Charybdis are employed to signify two equal dangers. Thus Horace says
+ h$ `4 I9 F2 {1 ~$ T2 |: Ban author trying to avoid Scylla, drifts into Charybdis,<em> i.e.</em>
6 N& O. v5 m0 p5 kseeking to avoid one fault, falls into another. The tale is that
) B+ c" l8 {% b: l+ w, B: z  f' i- s* cCharybdis stole the oxen of Hercules, was killed by lightning, and
  w1 X. ~) @5 ], p. kchanged into the gulf.</p>- }7 Q9 R! ?' U5 V% V" D% N
<p>“Thus when I shun Scylla, your father, I fall into Charybdis, your& W4 y5 P  H" i$ S) t% W
mother.” —<cite>Shakespeare: Merchant of Venice,</cite> iii. 5.5 H0 F1 z5 o9 ^  w: r/ n) q% `: {
</p>1 x: V  V* H' ]/ D8 @

" \, R" G4 i  c& ]' {<div class="source">Source: <cite>Dictionary of Phrase and Fable</cite>, E. Cobham Brewer, 1894</div>
5 X: v7 d' V9 n) I/ _5 {9 x
利用TextForever来提取文本3 r- q, [  D4 I5 [

) N$ s! g. K# U' r3 a-
# @) k, B9 q! p( U: u, A1 b; |* k  P3 D0 {: c2 m1 `8 U6 l4 T! y/ [
提取完毕,合并得到的16695个html,
! T- _1 X2 V2 E& @3 a) U3 w5 H9 Q8 Q+ b+ r+ U
这本词典的制作过程中,我思考了下,不用在“文件内容前加注文件名”,有的情况下,是需要这样做的,以方便提取keywords,经过测试,还是要在“文件内容后加空行”。
( F; w2 N4 I, @" [: w6 Y) c3 t5 j
8 C/ I" q8 k: L7 ~2 I: q" V得到dopf-src.txt,对这个txt进行操作,得到可build为mdx的txt。
. F- D) i* |& [
) N( t0 ~" Z8 v4. 制作mdx
! r$ _. T) e0 z合并后的文本长这样:5 _3 ?, @# N: y0 o+ x

4 x6 q* D6 \& v. d2 r& ], @0 {/ }5 X5 _
明显http://www.infoplease.com/dictionary/brewers/的词典是xml,由于MDict PC版不支持xml+css,我们要把xml标签替换为html标签。经过下面一系列的操作。% ]$ D8 ]9 _, \6 z. V- j9 e" V

# c) r. j7 }% i" Q8 n& g
4 ]! S$ [3 `9 d0 y处理后最终的文本是这样:
, n& g! \4 E% S4 A5 T/ x& f/ p. n0 q8 P
9 ^4 U5 Q* ^5 }& y/ o3 @6 ~
再简单写点css
3 b) ^9 C3 ?* |8 K; u) O7 K8 V" V# ^) h, W7 l
  [- G( n% w/ d
中途遇到些小问题,一个个解决,最后,成品:# D2 U! Z2 B8 u7 u

& I/ |6 h4 }, A2 M' y是不是比在线的稍微顺眼点呢?
/ r9 W: B8 K6 M3 v4 A' }! \4 zhttp://www.infoplease.com/dictionary/brewers/comb.html
1 Q5 y1 `5 S9 t4 b3 d
! E5 }& d6 R! k9 r1 [* T" w1 A  X* z+ o: M1 e. _
PS:虽然做完了,但是我发现了一些问题,从上面的截图中就可以看出来,有些词之间少了空格。暂无意修改,等有空改完了再分享。谁有兴趣改一改练练手的话,可以PM我,我把下载的网页发给你。
* g- t5 Y0 ~3 D$ \8 t

本帖被以下淘专辑推荐:

该用户从未签到

发表于 2013-11-14 16:26:41 | 显示全部楼层
此贴要顶!
  • TA的每日心情
    开心
    2018-1-27 00:16
  • 签到天数: 1 天

    [LV.1]初来乍到

    发表于 2013-11-15 23:30:45 来自手机 | 显示全部楼层
    老大您好。感谢您提供的教程。% O' W# C, J. Q* A  p/ z
    小弟按照您的教程,把第一步完成了,但是如何有效地完成第二步,就是您所说的抓取一千多个网页的那个步骤,小弟一头雾水,手动一个一个地输入也是一个方法,不过效率不高。不知道老大是否有批量获得每个单词网页的方法呢?烦请指点一二,多谢多谢。0 C! [9 V8 e, j! H4 [2 z- e; N: M: P! `

    / O1 T1 A# W$ A  a0 ^0 m小弟想抓取的网页如下:
    + g( m; Y  P8 k$ t& K* M) P; jhttp://zokugo-dict.com/
    " q/ c) l! d! ?4 A; P7 K, y" B6 r' u' k, g9 w1 F6 p7 O& k
    右边的五十音图就是索引部分。

    该用户从未签到

     楼主| 发表于 2013-11-16 14:14:53 | 显示全部楼层
    liuyunrushui 发表于 2013-11-15 23:30 % O1 f1 r- t4 z% c: d
    老大您好。感谢您提供的教程。
    9 ~/ h% @9 M" Q9 Y9 x# i# a小弟按照您的教程,把第一步完成了,但是如何有效地完成第二步,就是您所说 ...

    , v' P% O, V( @: ]3 D6 p4 ?3 P; N1 v9 Q3 m1 s
    cmd.exe; v4 m/ P( Z7 ]# C5 }, n

    7 g4 k& p8 R* c) J% n( {wget -i download.txt' D, q, c' H$ u
    所有网页链接在download.txt,参考http://baike.baidu.com/view/1312507.htm,也可以自己写程序抓。结合awk等等的话,其实可以更快,抓完也就制作完了。

    该用户从未签到

    发表于 2014-4-1 09:02:21 | 显示全部楼层
    thank you very much
    您需要登录后才可以回帖 登录 | 免费注册

    本版积分规则

    小黑屋|手机版|Archiver|PDAWIKI |网站地图

    GMT+8, 2025-5-3 06:07 , Processed in 0.022130 second(s), 23 queries .

    Powered by Discuz! X3.4

    © 2001-2023 Discuz! Team.

    快速回复 返回顶部 返回列表