TA的每日心情 | 开心 2019-8-21 08:44 |
|---|
签到天数: 163 天 [LV.7]常住居民III
|
发表于 2018-11-25 16:50:10
|
显示全部楼层
本帖最后由 mikeee 于 2018-11-25 18:08 编辑
# y9 z; A! D9 @ {8 S1 T [0 v L4 `! p% j8 u) d# W6 k
有一个办法应该可行:先用 Abbyy Finereader 转成 docx,docx再转成 htm。
d& R; [9 {1 N& `, s' N( n3 r5 w9 G' [3 g( U7 b4 I" [
我机器里没装Finereader,用在线 https://finereaderonline.com 做了十页(每天在线只能OCR十页),效果不错:htm里的页头自动消失。两列变成了单列,粗体保留,好像原pdf换行时的 hyphen 都去掉了,但原pdf里跨页的段落好像没有合并。
1 f' X ?# o; i8 i7 W+ [8 }- o9 F# _* A. c9 n6 O0 P; d# Q7 F
Chrome Devtools 大致看了看:css selector: p.Bodytext21 可定位所有的释义" h; Z* ~0 ^( b
css selector:p.Bodytext21>span.Bodytext2Bold 可定位释义里的粗体' I( f, r: C0 y; \: Q' j
8 S+ ^* t6 b/ t- {& w! }
贴不了图,发个 docx 和 htm 文件(仅10页) 百度盘链接: https://pan.baidu.com/s/15Qc4tQeWcePy7AhTJLiJXQ 提取码: encg
, h; Z( R1 Y3 N( [$ N. J& r' J% V, R: h3 B: i/ X6 W
折腾了一阵,这个 python3 码处理上面说的 htm 得到的东西大致可以做成 mdx
& l1 P, f3 X8 \) @" P( G9 o- '''word and phrase orgins test; I4 [. d- E% X
- '''' R8 d7 g) Z/ ^: l: g
- from pyquery import PyQuery as pq
; ` I6 w; h- \5 K( r! J
?( ~7 V B3 z* L% s- file = r'WordandPhraseOrigins.htm'
{0 v6 J! e" p - try:
2 c2 `% ]% v2 o) e* p" l. `% _ - html = open(file, 'rt', encoding='utf8').read()
# O$ Z( S$ e& k% w - except Exception as exc:
! s* h) W" d5 C - print('error: {}. Trying gb2312...'.format(exc))' N8 |% k. z/ {+ [, x3 y9 J: `
- try:+ W( `' q9 [: @; V% \% o, E
- html = open(file, 'rt', encoding='gb2312').read()
- r" ?" p' L0 Q' s1 u2 K& }( I( B! I - print('Looks good')
/ p0 A C! I- f8 E" P' E - except Exception as exc:
% S- U, |5 ]+ i! M/ L# `6 p! q - SystemExit('error: {}. Giving up...'.format(exc))
- l7 w" d; l0 \: k! O, u - doc = pq(html)
! j% U& ?0 Z/ G+ |8 k3 R9 d9 n
& J$ L. j" k3 W+ C3 C0 E$ n, q- css_text = 'p.Bodytext21'3 k- W! m3 ^* }
- css_bold = 'p.Bodytext21>span.Bodytext2Bold'5 t2 S5 I; g+ q
- ! z7 c: o+ k! R4 y/ ]5 q- F& B
- items = doc(css_text)8 Z' O* w! c0 q8 n
* b+ W$ V3 L0 [( h, O- text = doc(css_text).map(lambda idx, elm: pq(elm)(
9 X3 V5 r. x' d2 g# z - 'span.Bodytext2Bold').text() + ('(hw)\n' if pq(elm)('span.Bodytext2Bold').text() else '\n') + pq(elm)('span.Bodytext20').text())
! U" c" D y, b! X - print('\n\n'.join(text[:60]))! b+ M2 h4 q5 e' [1 e- Z
复制代码 上面码的输出大致这个样子:。。。, C' F# x# F' D# @9 E3 V- J
A-Rod.(hw)2 N. ^0 i8 C2 I# T* M
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.
$ W" u8 g. b/ F8 T, F5 n* X d
3 E# e. j ^& r* v& {around Cape Horn.(hw)
. @. T1 p7 Y' uAn expression once used in whaling communities to mean “being away on a whaling voyage.” One old poem went:. R1 J' F4 O( \ B/ I, J8 o/ \
! W \5 V$ j x4 e
( g7 D8 _9 P% |$ t; G$ j“I’ll tell your father, boys,” I cried To lads at play upon my lawn.9 m+ \8 H- o7 i2 a" S
# g4 B2 q: c/ s% y4 _% i; U' q3 x/ C% g# _0 Z4 A" U
They chorused back, “You’ll have to go Around Cape Horn.”9 C- ?; j' i e- e! m3 X
* h* k; ?. R) m4 r) W$ I F; raround the horn.(hw)
- Y; |, K& T+ D+ M" D- @: yIn 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.( {1 k1 @- u3 D
! ^5 j l6 {. h
arrant thief; knight errant.(hw)
7 ]" H, q1 p6 J, ] C6 {" i1 awas 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-: a- J; J# q& \% g
。。。
. }2 e* o3 r9 `" v& d1 j1 d 顺便安利一下 pyquery,是不是完爆正则、bs4、lxml ?
Z' C+ t! C7 m: W: v
0 v( r8 ?4 ~; A$ {
: g: q2 i b0 j- g6 ^ ^, B5 b ]) \$ m' U0 G) T9 Q
|
评分
-
1
查看全部评分
-
|