# Mac 自带词典 如何预览CSS

**URL:** <https://forum.freemdict.com/t/topic/8719>\
**Category:** 词典装饰排版交流分享\
**Created:** [2021 年10 月 9 日 09:42 UTC](https://forum.freemdict.com/t/topic/8719 "2021-10-09T09:42:36Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

作者： ![青稚Quentin](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/%E9%9D%92%E7%A8%9Aquentin/32/14413_2.png) [@青稚Quentin](https://forum.freemdict.com/u/%E9%9D%92%E7%A8%9AQuentin)\
发布日期： [2021 年10 月 9 日 09:42 UTC](https://forum.freemdict.com/t/topic/8719/1 "2021-10-09T09:42:36Z")

</div>

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

 ![CleanShot 2021-10-09 at 17.53.58@2x](https://forumcdn.freemdict.com/uploads/default/original/3X/2/b/2b305b7804a0027b9be456c18ead2cfbb5598e4a.jpeg)

---

<div class="post-metadata">

作者： ![okayer](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/okayer/32/16083_2.png) [@okayer](https://forum.freemdict.com/u/okayer)\
发布日期： [2021 年10 月 9 日 14:39 UTC](https://forum.freemdict.com/t/topic/8719/2 "2021-10-09T14:39:24Z")

</div>

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

---

<div class="post-metadata">

作者： ![青稚Quentin](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/%E9%9D%92%E7%A8%9Aquentin/32/14413_2.png) [@青稚Quentin](https://forum.freemdict.com/u/%E9%9D%92%E7%A8%9AQuentin)\
发布日期： [2021 年10 月 9 日 23:28 UTC](https://forum.freemdict.com/t/topic/8719/3 "2021-10-09T23:28:42Z")

</div>

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

---

<div class="post-metadata">

作者： ![okayer](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/okayer/32/16083_2.png) [@okayer](https://forum.freemdict.com/u/okayer)\
发布日期： [2021 年10 月 10 日 01:24 UTC](https://forum.freemdict.com/t/topic/8719/4 "2021-10-10T01:24:32Z")

</div>

```auto
# -*- 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', ''))

```

---

<div class="post-metadata">

作者： ![青稚Quentin](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/%E9%9D%92%E7%A8%9Aquentin/32/14413_2.png) [@青稚Quentin](https://forum.freemdict.com/u/%E9%9D%92%E7%A8%9AQuentin)\
发布日期： [2021 年10 月 10 日 01:41 UTC](https://forum.freemdict.com/t/topic/8719/5 "2021-10-10T01:41:22Z")

</div>

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

---

<div class="post-metadata">

作者： ![青稚Quentin](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/%E9%9D%92%E7%A8%9Aquentin/32/14413_2.png) [@青稚Quentin](https://forum.freemdict.com/u/%E9%9D%92%E7%A8%9AQuentin)\
发布日期： [2021 年10 月 10 日 01:43 UTC](https://forum.freemdict.com/t/topic/8719/6 "2021-10-10T01:43:32Z")

</div>

![CleanShot 2021-10-10 at 09.42.46](https://forumcdn.freemdict.com/uploads/default/original/3X/7/7/7707ca9838d1233f44f7b5bb51cd9e8d49381764.gif)

---

<div class="post-metadata">

作者： ![okayer](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/okayer/32/16083_2.png) [@okayer](https://forum.freemdict.com/u/okayer)\
发布日期： [2021 年10 月 10 日 01:53 UTC](https://forum.freemdict.com/t/topic/8719/7 "2021-10-10T01:53:25Z")

</div>

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

---

<div class="post-metadata">

作者： ![青稚Quentin](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/%E9%9D%92%E7%A8%9Aquentin/32/14413_2.png) [@青稚Quentin](https://forum.freemdict.com/u/%E9%9D%92%E7%A8%9AQuentin)\
发布日期： [2021 年10 月 10 日 02:11 UTC](https://forum.freemdict.com/t/topic/8719/8 "2021-10-10T02:11:38Z")

</div>

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

---

<div class="post-metadata">

作者： ![okayer](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/okayer/32/16083_2.png) [@okayer](https://forum.freemdict.com/u/okayer)\
发布日期： [2021 年10 月 10 日 02:17 UTC](https://forum.freemdict.com/t/topic/8719/9 "2021-10-10T02:17:51Z")

</div>

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

 ![Screen Shot 2021-10-10 at 10.14.59 AM](https://forumcdn.freemdict.com/uploads/default/original/3X/a/8/a8208fd9ac9a37e10e50e9514ee6eb1b67c6adca.png)

---

<div class="post-metadata">

作者： ![青稚Quentin](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/%E9%9D%92%E7%A8%9Aquentin/32/14413_2.png) [@青稚Quentin](https://forum.freemdict.com/u/%E9%9D%92%E7%A8%9AQuentin)\
发布日期： [2021 年10 月 10 日 02:23 UTC](https://forum.freemdict.com/t/topic/8719/10 "2021-10-10T02:23:47Z")

</div>

我使用python2 也不行。 我的版本是 macos Bia Sur 版本11.5.2  
传输链接：[文件下载-奶牛快传 Download ｜CowTransfer](https://cowtransfer.com/s/87a5debc3d2e46) 或 打开【奶牛快传】[cowtransfer.com](http://cowtransfer.com) 使用传输口令：h1ka5x 提取；

---

<div class="post-metadata">

作者： ![okayer](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/okayer/32/16083_2.png) [@okayer](https://forum.freemdict.com/u/okayer)\
发布日期： [2021 年10 月 10 日 02:43 UTC](https://forum.freemdict.com/t/topic/8719/11 "2021-10-10T02:43:30Z")

</div>

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

[sod6.html.tar.gz](https://forum.freemdict.com/uploads/short-url/hwhxEkc2p3T5ReYpIDUx7XS7zHE.gz) (6.5 KB)

---

<div class="post-metadata">

作者： ![青稚Quentin](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/%E9%9D%92%E7%A8%9Aquentin/32/14413_2.png) [@青稚Quentin](https://forum.freemdict.com/u/%E9%9D%92%E7%A8%9AQuentin)\
发布日期： [2021 年10 月 10 日 02:43 UTC](https://forum.freemdict.com/t/topic/8719/12 "2021-10-10T02:43:51Z")

</div>

非常感谢！！

---

<div class="post-metadata">

作者： ![青稚Quentin](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/%E9%9D%92%E7%A8%9Aquentin/32/14413_2.png) [@青稚Quentin](https://forum.freemdict.com/u/%E9%9D%92%E7%A8%9AQuentin)\
发布日期： [2021 年10 月 10 日 05:35 UTC](https://forum.freemdict.com/t/topic/8719/13 "2021-10-10T05:35:53Z")

</div>

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

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

```auto
python2 a_dict.py

```

```auto
# 得到结果
⇒ <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` ，得到如下结果

```auto
/-	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 信息，目前显示的不完整， 滚动条拉到最上面也只能看到其中一部分代码

---

<div class="post-metadata">

作者： ![青稚Quentin](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/%E9%9D%92%E7%A8%9Aquentin/32/14413_2.png) [@青稚Quentin](https://forum.freemdict.com/u/%E9%9D%92%E7%A8%9AQuentin)\
发布日期： [2021 年10 月 10 日 05:45 UTC](https://forum.freemdict.com/t/topic/8719/14 "2021-10-10T05:45:00Z")

</div>

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

 ![CleanShot 2021-10-10 at 13.44.05@2x](https://forumcdn.freemdict.com/uploads/default/original/3X/5/1/5139772a275e585bc657e32d59f45dbd5e4ae905.jpeg)

---

<div class="post-metadata">

作者： ![okayer](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/okayer/32/16083_2.png) [@okayer](https://forum.freemdict.com/u/okayer)\
发布日期： [2021 年10 月 10 日 06:21 UTC](https://forum.freemdict.com/t/topic/8719/15 "2021-10-10T06:21:35Z")

</div>

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

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

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

```

 ![Screen Shot 2021-10-10 at 2.17.54 PM](https://forumcdn.freemdict.com/uploads/default/original/3X/8/6/860ae51c176dc09a56314fb9e9382462fecd5bb2.png)

> **[关闭iterm2中对于行数的限制\_你的微笑像拥抱的博客-CSDN博客\_iterm2 设置log行数](https://blog.csdn.net/dfydn/article/details/105625029)**
>
> iTerm2 默认的行数限制，超过 1000 的部分就被隐藏不显示了。处理方式：打开 Preferences窗口，点击 Profiles，右侧点击 Terminal，在 Scrollback line 右边勾选 Ulimited scrollback。...

---

<div class="post-metadata">

作者： ![青稚Quentin](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/%E9%9D%92%E7%A8%9Aquentin/32/14413_2.png) [@青稚Quentin](https://forum.freemdict.com/u/%E9%9D%92%E7%A8%9AQuentin)\
发布日期： [2021 年10 月 10 日 10:13 UTC](https://forum.freemdict.com/t/topic/8719/16 "2021-10-10T10:13:47Z")

</div>

成功了 ， 非常感谢！！ 👏
