# GoldenDict查询之掐头取尾

**URL:** <https://forum.freemdict.com/t/topic/44590>\
**Category:** GoldenDict-ng\
**Tags:** goldendict, 技术\
**Created:** [2026 年7 月 14 日 13:22 UTC](https://forum.freemdict.com/t/topic/44590 "2026-07-14T13:22:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

作者： ![yx\_wh](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/yx_wh/32/77200_2.png) [@yx\_wh](https://forum.freemdict.com/u/yx_wh)\
发布日期： [2026 年7 月 14 日 13:22 UTC](https://forum.freemdict.com/t/topic/44590/1 "2026-07-14T13:22:07Z")

</div>

GoldenDict支持把程序的输出作为辞典来使用。一位知乎用户发表了相关文章：  
[伟大献礼（误）致 GoldenDict 德语辞典用户](https://zhuanlan.zhihu.com/p/31102148)  
我想了想，英语跟德语同属于日耳曼语，这个完全🉑以拿来英语和德语共用嘛！于是在AI辅助和实际探查GoldenDict超链接的格式后书写如下：

```auto
import sys
import urllib.parse # 别忘了加这个库，用来处理特殊字符

def output(o):
    # 对查询词进行URL编码，防止空格、&等特殊字符导致截断
    encoded = urllib.parse.quote(o)
    # 关键改动：href 改成 gdlookup:// 协议
    fullstr = f'<meta charset="utf-8"><a href="gdlookup://localhost/{encoded}">{o}</a>'
    sys.stdout.buffer.write(fullstr.encode('utf-8'))

s = sys.argv[1].strip().split(' ')

# 仅保留：划了超过2个词 → 取首尾拼接
if len(s) > 2:
    output(s[0] + ' ' + s[-1]) # 或者直接拼成 pick up / sieht fern

sys.exit(0)

```

然后在GoldenDict的编辑-词典-词典来源-程序中加入一个新的项：  
类型：HTML  
名称：掐头取尾✂  
命令行：python3 /程序所在的文件夹/head-tail-splitter.py %GDWORD%

现在实战一下：  
He picked the phone up and dialled.  
现在先选中“picked the phone up”，进行查询。「掐头取尾✂」提示“picked up”。单击，hunspell拼写文件给出pick up。成功查询。

对于德语也是同理，但是注意德语需要有一个路由词典，能把诸如“sieht fern”这样的表达给路由到“fernsehen”上。而这样的词典我也确实发现了——Babylon German-English（NEW\_Babylon\_German\_English\_dictionary.BGL）或者德文版《维基词典》。前者是硬跳转，后者给出链接。
