TA的每日心情 | 开心 2019-8-21 08:44 |
|---|
签到天数: 163 天 [LV.7]常住居民III
|
发表于 2018-11-25 16:50:10
|
显示全部楼层
本帖最后由 mikeee 于 2018-11-25 18:08 编辑
2 p' D, ^3 C* ~7 o) Q, X) i; c8 ^9 b& p9 p! Z- ] ~ Z
有一个办法应该可行:先用 Abbyy Finereader 转成 docx,docx再转成 htm。) j" R- u/ n2 W! K
' \9 c; n: h, D7 ?) h5 N我机器里没装Finereader,用在线 https://finereaderonline.com 做了十页(每天在线只能OCR十页),效果不错:htm里的页头自动消失。两列变成了单列,粗体保留,好像原pdf换行时的 hyphen 都去掉了,但原pdf里跨页的段落好像没有合并。- u) o9 O6 W- Q+ E
& U) Y; B7 O1 P. k: z& M
Chrome Devtools 大致看了看:css selector: p.Bodytext21 可定位所有的释义2 W" }. `' @3 e+ K- r y
css selector:p.Bodytext21>span.Bodytext2Bold 可定位释义里的粗体: g+ l+ @2 d7 ^; w
9 I1 q% u1 T7 W% W贴不了图,发个 docx 和 htm 文件(仅10页) 百度盘链接: https://pan.baidu.com/s/15Qc4tQeWcePy7AhTJLiJXQ 提取码: encg 9 F+ s7 a/ i) }! h) Y% G: Y/ p
$ {5 g! W3 J! Z3 f& h' f6 G折腾了一阵,这个 python3 码处理上面说的 htm 得到的东西大致可以做成 mdx
) J* `9 g6 {) D" l1 J7 o- '''word and phrase orgins test; m- ~0 Q0 Q& v9 @ [* u
- '''
( Q. J' F. j5 Z. X - from pyquery import PyQuery as pq
8 H s/ G8 {1 V! E8 l
( c7 J4 M* g j7 Q* c- file = r'WordandPhraseOrigins.htm'
# h2 h: ]8 K( L$ O+ A% c - try:
2 _. Z$ f, J; f; l: O" P( L, R9 |3 f - html = open(file, 'rt', encoding='utf8').read()9 _% m6 j3 E/ _! V N/ K. i
- except Exception as exc:0 q. W! K4 y$ L' L5 W5 \+ }& c. K- i
- print('error: {}. Trying gb2312...'.format(exc))
. @8 I8 X( u! m( { - try:
: B% }' |7 o( q, T0 m( A - html = open(file, 'rt', encoding='gb2312').read()
x, _$ s; D& ~" u) P5 E/ ` - print('Looks good')) G: ]8 d4 E# {. j
- except Exception as exc:- y1 H, }: I) h: f6 z
- SystemExit('error: {}. Giving up...'.format(exc))3 V, H* p }3 J
- doc = pq(html); L# H* X V8 O" n7 _2 W7 g3 T
- 6 |# R2 _6 K" P7 X" ^
- css_text = 'p.Bodytext21'
/ V# H5 g; k1 i; E' X) S - css_bold = 'p.Bodytext21>span.Bodytext2Bold'+ i, t6 k' [, W6 ~! ^
- 7 T9 U0 i. f; t
- items = doc(css_text)
R, j! u f/ I! u1 n% Q J - / P/ {4 O' K+ y
- text = doc(css_text).map(lambda idx, elm: pq(elm)(- ]6 T8 i! F3 _ X( @
- 'span.Bodytext2Bold').text() + ('(hw)\n' if pq(elm)('span.Bodytext2Bold').text() else '\n') + pq(elm)('span.Bodytext20').text())
* s5 z& Q5 Z$ X) j9 \ - print('\n\n'.join(text[:60])): V2 F: E- o! Y B
复制代码 上面码的输出大致这个样子:。。。
3 ^2 E9 y$ _6 x$ K' {8 S/ @8 kA-Rod.(hw)" }4 h2 T* V4 }0 W9 v9 W
People 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.
* S- s6 [. l+ {; e v3 p1 l& d/ ]6 ]; `7 {7 z: q6 p% D6 X
around Cape Horn.(hw)+ d6 H! k, t$ Z# t) `- @6 q! X1 P
An expression once used in whaling communities to mean “being away on a whaling voyage.” One old poem went:+ ~# |6 z0 D/ U+ {
- V" `+ m! l% d$ y! T# u
: K: V) |, f" S' ?# j“I’ll tell your father, boys,” I cried To lads at play upon my lawn.+ M; l' u# a; q8 v8 X
5 k. q6 b7 N1 W1 u) I6 S$ d" { B
# o5 p( \6 Q' l) {9 |1 a
They chorused back, “You’ll have to go Around Cape Horn.”
2 W9 h4 q; [1 U3 ?6 D1 n
9 w/ D- A# s7 Z( ]9 [2 e* Jaround the horn.(hw)' a9 C( k" Y$ V4 @ o
In 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.( \0 M. l" r4 L# x
% E8 z* s9 z5 e# m7 f" J
arrant thief; knight errant.(hw)3 F8 m/ s$ A! p+ L. ?
was 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-
% H/ v# O1 J$ M。。。 2 l! o3 ?6 B) {
顺便安利一下 pyquery,是不是完爆正则、bs4、lxml ?
, U5 w' [1 W+ B* g7 {% c
; a* N$ n ]+ O. H! Q
! v1 N, i9 u; t! b6 z0 o
7 ^& D. D) ] g2 t |
评分
-
1
查看全部评分
-
|