TA的每日心情 | 开心 2019-8-21 08:44 |
|---|
签到天数: 163 天 [LV.7]常住居民III
|
发表于 2018-11-25 16:50:10
|
显示全部楼层
本帖最后由 mikeee 于 2018-11-25 18:08 编辑
+ ^7 t; @+ U/ |6 X9 c! N/ f& w2 h3 V
有一个办法应该可行:先用 Abbyy Finereader 转成 docx,docx再转成 htm。
! i/ @1 X3 M0 {) t' C3 C- Y1 ~# W: W0 j& m% H- h
我机器里没装Finereader,用在线 https://finereaderonline.com 做了十页(每天在线只能OCR十页),效果不错:htm里的页头自动消失。两列变成了单列,粗体保留,好像原pdf换行时的 hyphen 都去掉了,但原pdf里跨页的段落好像没有合并。+ p- T& C* l/ H- g- b
. ? ?* q: y+ ^# X9 ?& f
Chrome Devtools 大致看了看:css selector: p.Bodytext21 可定位所有的释义# y$ ] G) i& x3 ^
css selector:p.Bodytext21>span.Bodytext2Bold 可定位释义里的粗体5 h% _( y0 G& i$ x
7 t$ U3 g1 \; S+ @. Z9 z贴不了图,发个 docx 和 htm 文件(仅10页) 百度盘链接: https://pan.baidu.com/s/15Qc4tQeWcePy7AhTJLiJXQ 提取码: encg 6 r B" {$ k8 o V2 A
6 |( _; ]; ]% J
折腾了一阵,这个 python3 码处理上面说的 htm 得到的东西大致可以做成 mdx& `8 j1 g# Y6 A' g
- '''word and phrase orgins test: e* Q( q4 ^5 N2 s
- '''
9 T4 N) Y# ?0 T* l' E5 o - from pyquery import PyQuery as pq0 @+ g/ l4 X: N% n \0 x
% J% E8 Y7 Q/ N& U1 s2 z! C% S- file = r'WordandPhraseOrigins.htm'; I( u% M4 B! H
- try:/ o# _) v |% W1 E0 S
- html = open(file, 'rt', encoding='utf8').read(): D+ `6 Z, ^& C2 D; Q. A; p
- except Exception as exc:% D" G' J4 x' G; w6 F1 \
- print('error: {}. Trying gb2312...'.format(exc)); u5 [; @% X% ~6 x2 y8 b9 z
- try:! h) b# h3 I8 u' ^% `
- html = open(file, 'rt', encoding='gb2312').read()
5 v2 H2 W8 j2 Z - print('Looks good')% T+ \+ s( k3 x. u, E6 C% b6 ]
- except Exception as exc:/ B( p. `; F/ i, q% r! A D
- SystemExit('error: {}. Giving up...'.format(exc))0 u. } U/ ]/ n5 n& C
- doc = pq(html)! L5 h" V3 I1 c+ P, X) w% ~
$ A0 H( u; T+ A- css_text = 'p.Bodytext21'
% H, }) x: K! s! p" z L& [ - css_bold = 'p.Bodytext21>span.Bodytext2Bold', l' T3 [! {9 M0 {) d1 R
( ?3 a+ c! i- I- items = doc(css_text)
3 a l7 j$ o+ y6 j' } - 8 o. x7 E8 X8 x3 q% a. u4 d6 ^
- text = doc(css_text).map(lambda idx, elm: pq(elm)(0 z4 F8 |7 O/ j* c
- 'span.Bodytext2Bold').text() + ('(hw)\n' if pq(elm)('span.Bodytext2Bold').text() else '\n') + pq(elm)('span.Bodytext20').text()): P- m& g9 P; }! G) D( O
- print('\n\n'.join(text[:60]))( t! @4 c' v; }
复制代码 上面码的输出大致这个样子:。。。
7 y) Y+ `* T: w$ L' b) u4 jA-Rod.(hw)
6 O9 {0 N+ I- y: s9 E2 g3 zPeople who have little or no knowledge of baseball might have trouble with these initials. They are short for Alex Rodriguez, the famous Yankee baseball star.) @- L$ s4 ]4 j, y* J8 X
" E1 f; c2 j V* w- \% _around Cape Horn.(hw)1 A' }9 A- B( T, a7 A9 Q. g }
An expression once used in whaling communities to mean “being away on a whaling voyage.” One old poem went:2 ^: _1 g- ^- g& n' w! c& T
( z' U5 v3 [4 B& i2 F9 F
6 c6 s/ N! ^3 {3 V2 _2 T& `“I’ll tell your father, boys,” I cried To lads at play upon my lawn.4 ^3 Q) x% h% n1 D0 z' ~
3 G9 s. ]+ n" t* d/ B
4 g W0 B! h+ ^4 O2 m3 k: z7 AThey chorused back, “You’ll have to go Around Cape Horn.”
6 Y$ ]5 q. h7 K1 h" H7 f* i; y) o% U9 B
around the horn.(hw)
: ]+ s9 J/ \ H$ eIn the days of the tall ships any sailor who had sailed around Cape Horn was entitled to spit to windward; otherwise, it was a serious infraction of nautical rules of conduct. Thus, the permissible practice of spitting to windward was called Cape Horn isn’t so named because it is shaped like a horn. Captain Schouten, the Dutch navigator who first rounded it in 1616, named it after Hoorn, his birthplace in northern Holland., e! y9 U* k5 P( V
. f/ r: y5 ^/ C4 t: H* ~- }' J4 darrant thief; knight errant.(hw)
8 [5 m2 E! N& cwas originally just a variation of nomadic or vagabond, the word best known in a knight who roamed the country performing good deeds. But from its persistent use in expressions such as an a thief who roamed the countryside holding up victims, came to mean thorough, downright, or out-" ]5 n7 d7 K& R! }
。。。 0 U6 E% R" a1 P. f+ {+ E- o
顺便安利一下 pyquery,是不是完爆正则、bs4、lxml ?
4 }2 }8 a' d9 t: K e, C7 S; t' f9 B
6 p' m4 A* L% C9 e* L* d6 T& p' d( T; C n' s5 }
7 T( c+ A B3 G3 K3 [: `0 }
|
评分
-
1
查看全部评分
-
|