# 如何精简在线词典中的页面元素

**URL:** <https://forum.freemdict.com/t/topic/26831>\
**Category:** 软件经验交流展望\
**Tags:** python, 在线词典\
**Created:** [2024 年2 月 20 日 12:10 UTC](https://forum.freemdict.com/t/topic/26831 "2024-02-20T12:10:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![clavin](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/clavin/32/57300_2.png) [@clavin](https://forum.freemdict.com/u/clavin)\
**Post date:** [2024 年2 月 20 日 12:10 UTC](https://forum.freemdict.com/t/topic/26831/1 "2024-02-20T12:10:04Z")

</div>

![截图 2024-02-20 18-14-01](https://forumcdn.freemdict.com/uploads/default/original/3X/3/0/306c1ea625c8f07afa8e2ce3930c37dbda86f672.png)

上图显示的是我一开始写这个小程序的目标，只留下想显示的元素，其他统统干掉，方法是用python爬取词典查询结果页面后，引用外部样式文件来隐藏网页元素，编程思路来源于DictTango，为其点赞。

下面是设置方式，路径和文件名请设置成自己电脑上的：

 ![截图 2024-02-20 19-49-15](https://forumcdn.freemdict.com/uploads/default/original/3X/0/3/03872f00faee638ba5f80bfcf63f6461feb4c9e2.png)

程序写的不乍的，但希望这个小程序能帮助到有这方面需求的朋友。如果有大佬有更好的解决方法，请不吝赐教。

---

<div class="post-metadata">

**Author:** ![clavin](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/clavin/32/57300_2.png) [@clavin](https://forum.freemdict.com/u/clavin)\
**Post date:** [2024 年2 月 21 日 02:22 UTC](https://forum.freemdict.com/t/topic/26831/2 "2024-02-21T02:22:49Z")

</div>

goldendict-webengine版可以将css样式写入article-style.css，放在配置文件夹中生效，也就是：python获取查询结果，goldendict引入样式，配合完美。

 ![image](https://forumcdn.freemdict.com/uploads/default/original/3X/3/2/32ed0f173df8790900131648257006c1c7d585a8.png)

[ojad.py](https://forum.freemdict.com/uploads/short-url/kllGJiUJdK6OQ1ZOjBML7XnOanm.py) (2.3 KB)  
[article-style.css](https://forum.freemdict.com/uploads/short-url/nblEWNSA9Fz3RhtxNrDDjZT5L2x.css) (183 字节)

---

<div class="post-metadata">

**Author:** ![tiep](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/t/c77e96/32.png) [@tiep](https://forum.freemdict.com/u/tiep)\
**Post date:** [2024 年2 月 24 日 05:30 UTC](https://forum.freemdict.com/t/topic/26831/3 "2024-02-24T05:30:35Z")

</div>

> **[Specificity - CSS: Cascading Style Sheets | MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity#precedence_over_third-party_css)**
>
> Specificity is the algorithm used by browsers to determine the CSS declaration that is the most relevant to an element, which in turn, determines the property value to apply to the element. The specificity algorithm calculates the weight of a CSS...

就性能而言，运行 Python 脚本进行单词查询是一种巨大的浪费。可以考虑将 Python 函数封装在服务中，然后通过 HTTP 或 IPC 调用（至少应避免使用 bs4 库）。

---

<div class="post-metadata">

**Author:** ![clavin](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/clavin/32/57300_2.png) [@clavin](https://forum.freemdict.com/u/clavin)\
**Post date:** [2024 年2 月 25 日 00:22 UTC](https://forum.freemdict.com/t/topic/26831/4 "2024-02-25T00:22:09Z")

</div>

说的是网页，但透过Python，连接自己的数据库，网站，可以定制任何想显示在词典上的内容，打造成查询终端
