Mac 自带词典 如何预览CSS

macOS 自带词典 , 如何查看html +css 效果呢 我需要调整 css , 但无法查看效果 。目前只能在css文件 修改颜色 然后复制到词典文件夹 打开词典查看效果 。 其他的css 没有看到对应的class 无法修改

SOED6.dictionary
- Contents
- Body.data
- COVERSOED6.png
- DefaultStyle.css
- EntryID.data
- EntryID.index
- Info.plist
- KeyText.data
- KeyText.index

目前在修改 SOED6

我一般都直接編輯DefaultStyle.css,保存css,重啟詞典。也沒什麼繁瑣的。如果你做大的修改,也可以導出詞條的html,直接瀏覽器調試。

1 个赞

怎么导出词条的html呢? MDX格式我知道在 Goldendict 里面可以导出。

# -*- coding: utf-8 -*-
# https://gist.githubusercontent.com/josephg/5e134adf70760ee7e49d/raw/cf9787c363e40148d9fe58aff50d63b6fbee7341/0dedict.py
# Thanks to commenters for providing the base of this much nicer implementation!
# Save and run with $ python 0dedict.py
# You may need to hunt down the dictionary files yourself and change the awful path string below.
# This works for me on MacOS 10.14 Mohave

from struct import unpack
from zlib import decompress
from signal import signal, SIGPIPE, SIG_DFL
signal(SIGPIPE,SIG_DFL)
import re
filename='/System/Library/AssetsV2/./com_apple_MobileAsset_DictionaryServices_dictionaryOSX/b3b86a3a3219ad056e9d9bedf1c3f5572e248976.asset/AssetData/Simplified Chinese - English.dictionary/Contents/Resources/Body.data'

f = open(filename, 'rb')

def gen_entry():
    f.seek(0x40)
    limit = 0x40 + unpack('i', f.read(4))[0]
    f.seek(0x60)
    while f.tell()<limit:
        sz, = unpack('i', f.read(4))
        buf = decompress(f.read(sz)[8:])

        pos = 0
        while pos < len(buf):
                try:
                    chunksize, = unpack('i', buf[pos:pos+4])
                    pos += 4

                    entry = buf[pos:pos+chunksize]
                    title = re.search('d:title="(.*?)"', entry).group(1)
                    yield title, entry

                    pos += chunksize
                except:
                    print(entry)
                    pass

for word, definition in gen_entry():
    print(word+"\t"+ definition.replace('\n', '').replace('\r', ''))

我尝试了 目前终端不停的给我返回 b’y>/n’ 是否正常呢, 生成的文件在什么位置呢 是否在 filename 目录下

CleanShot 2021-10-10 at 09.42.46

本來是用python2跑,輸出重定向一下就可以。

我在文件里 加入 #!/usr/local/bin/Python3 还是返回 b’y>/n’

用python2看看呢,新的macos 詞典格式變了?我用的10.15 。或者你上傳個詞典

我使用python2 也不行。 我的版本是 macos Bia Sur 版本11.5.2
传输链接:文件下载-奶牛快传 Download |CowTransfer 或 打开【奶牛快传】cowtransfer.com 使用传输口令:h1ka5x 提取;

python2沒問題,python3就會像你那樣。。。我提取了eat詞條,chrome直接調試就行。

sod6.html.tar.gz (6.5 KB)

非常感谢!!

我想问一下 , 你用 python 0dict.py |head ,是提取的词条吗?

我现在可以用下面的命令生成成功了

python2 a_dict.py
# 得到结果
⇒ <i>Main Entry</i>: <a href="x-dictionary:d:shilling#s266060:SOED6">shilling</a></d:entry>
1,000,080	ntry xmlns:d="http://www.apple.com/DTDs/DictionaryService-1.0.rng" id="_2" d:title="1,000,080"><h1>1,000,080</h1><span class="CQIL">1,000,080</span> ⇒ <i>Main Entry</i>: <a href="x-dictionary:d:million#s217090:SOED6">million</a></d:entry>
1020	ntry xmlns:d="http://www.apple.com/DTDs/DictionaryService-1.0.rng" id="_3" d:title="1020"><h1>1020</h1><span class="CQIL">1020</span> ⇒ <i>Main Entry</i>: <a href="x-dictionary:d:thousand#s288111:SOED6">thousand</a></d:entry>
1020th	ntry xmlns:d="http://www.apple.com/DTDs/DictionaryService-1.0.rng" id="_4" d:title="1020th"><h1>1020th</h1><span class="CQIL">1020th</span> ⇒ <i>Main Entry</i>: <a href="x-dictionary:d:thousand#s288116:SOED6">thousand</a></d:entry>
105 octane	ntry xmlns:d="http://www.apple.com/DTDs/DictionaryService-1.0.rng" id="_5" d:title="105 octane"><h1>105 octane</h1><span class="CQIL">105 octane</span> ⇒ <i>Main Entry</i>: <a href="x-dictionary:d:octane#s226768:SOED6">octane</a></d:entry>
1150	ntry xmlns:d="http://www.apple.com/DTDs/DictionaryService-1.0.rng" id="_6" d:title="1150"><h1>1150</h1><span class="CQIL">1150</span> ⇒ <i>Main Entry</i>: <a href="x-dictionary:d:eleven#s172687:SOED6">eleven</a></d:entry>
120	ntry xmlns:d="http://www.apple.com/DTDs/DictionaryService-1.0.rng" id="_7" d:title="120"><h1>120</h1><span class="CQIL">120</span> ⇒ <i>Main Entry</i>: <a href="x-dictionary:d:hundred#s194788:SOED6">hundred</a></d:entry>
1200	ntry xmlns:d="http://www.apple.com/DTDs/DictionaryService-1.0.rng" id="_8" d:title="1200"><h1>1200</h1><span class="CQIL">1200</span> ⇒ <i>Main Entry</i>: <a href="x-dictionary:d:hundred#s194796:SOED6">hundred</a></d:entry>
120th	ntry xmlns:d="http://www.apple.com/DTDs/DictionaryService-1.0.rng" id="_9" d:title="120th"><h1>120th</h1><span class="CQIL">120th</span> ⇒ <i>Main Entry</i>: <a href="x-dictionary:d:hundred#s194793:SOED6">hundred</a></d:entry>
1260

然后我使用 命令 python2 a_dict.py |head ,得到如下结果

/-	ntry xmlns:d="http://www.apple.com/DTDs/DictionaryService-1.0.rng" id="_1" d:title="/-"><h1>/-</h1><span class="CQIL">/-</span> ⇒ <i>Main Entry</i>: <a href="x-dictionary:d:shilling#s266060:SOED6">shilling</a></d:entry>
1,000,080	ntry xmlns:d="http://www.apple.com/DTDs/DictionaryService-1.0.rng" id="_2" d:title="1,000,080"><h1>1,000,080</h1><span class="CQIL">1,000,080</span> ⇒ <i>Main Entry</i>: <a href="x-dictionary:d:million#s217090:SOED6">million</a></d:entry>
1020	ntry xmlns:d="http://www.apple.com/DTDs/DictionaryService-1.0.rng" id="_3" d:title="1020"><h1>1020</h1><span class="CQIL">1020</span> ⇒ <i>Main Entry</i>: <a href="x-dictionary:d:thousand#s288111:SOED6">thousand</a></d:entry>
1020th	ntry xmlns:d="http://www.apple.com/DTDs/DictionaryService-1.0.rng" id="_4" d:title="1020th"><h1>1020th</h1><span class="CQIL">1020th</span> ⇒ <i>Main Entry</i>: <a href="x-dictionary:d:thousand#s288116:SOED6">thousand</a></d:entry>
105 octane	ntry xmlns:d="http://www.apple.com/DTDs/DictionaryService-1.0.rng" id="_5" d:title="105 octane"><h1>105 octane</h1><span class="CQIL">105 octane</span> ⇒ <i>Main Entry</i>: <a href="x-dictionary:d:octane#s226768:SOED6">octane</a></d:entry>
1150	ntry xmlns:d="http://www.apple.com/DTDs/DictionaryService-1.0.rng" id="_6" d:title="1150"><h1>1150</h1><span class="CQIL">1150</span> ⇒ <i>Main Entry</i>: <a href="x-dictionary:d:eleven#s172687:SOED6">eleven</a></d:entry>
120	ntry xmlns:d="http://www.apple.com/DTDs/DictionaryService-1.0.rng" id="_7" d:title="120"><h1>120</h1><span class="CQIL">120</span> ⇒ <i>Main Entry</i>: <a href="x-dictionary:d:hundred#s194788:SOED6">hundred</a></d:entry>
1200	ntry xmlns:d="http://www.apple.com/DTDs/DictionaryService-1.0.rng" id="_8" d:title="1200"><h1>1200</h1><span class="CQIL">1200</span> ⇒ <i>Main Entry</i>: <a href="x-dictionary:d:hundred#s194796:SOED6">hundred</a></d:entry>
120th	ntry xmlns:d="http://www.apple.com/DTDs/DictionaryService-1.0.rng" id="_9" d:title="120th"><h1>120th</h1><span class="CQIL">120th</span> ⇒ <i>Main Entry</i>: <a href="x-dictionary:d:hundred#s194793:SOED6">hundred</a></d:entry>
1260	ntry xmlns:d="http://www.apple.com/DTDs/DictionaryService-1.0.rng" id="_a" d:title="1260"><h1>1260</h1><span class="CQIL">1260</span> ⇒ <i>Main Entry</i>: <a href="x-dictionary:d:twelve#s295020:SOED6">twelve</a></d:entry>
Exception IOError: (32, 'Broken pipe') in <generator object gen_entry at 0x10ccb7a00> ignored
Traceback (most recent call last):
  File "a_dict.py", line 41, in <module>
    print(word+"\t"+ definition.replace('\n', '').replace('\r', ''))
IOError: [Errno 32] Broken pipe

我有几个问题 ,希望解惑。

  1. 我应该输入什么命令, 来提取某个词条的html 比如 well 单词

  2. 目前我的文件应该还存在问题, 可能因为在iterm上输出的 html 代码太多没有显示完整的代码 所以我没有发现有错误 。 然后用 python2 a_dict.py |head 才发现有报错

  3. iterm2 打印在终端的 html 信息,目前显示的不完整, 滚动条拉到最上面也只能看到其中一部分代码

然后 我的结果是这样 看起来跟你的 html 并不一样

上面腳本我更新了一下,head的報錯可以忽略的。

# 導出文本
python2 a_dict.py > soed6.txt

# 查詢某個單詞,比如well。注意well後面的空白為TAB符,網頁顯示不出來
grep -E "^well     "   soed6.txt

1 个赞

成功了 , 非常感谢!! :clap:

1 个赞