python

头条号:https://mp.toutiao.com/profile_v4/graphic/publish
百家号:https://baijiahao.baidu.com/builder/rc/edit?type=news

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# pip install jaraco.clipboard
from jaraco import clipboard

html = """
<html>

<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>

<body>
<div class="dpu8C _2kCxD "><span class="bjh-p">有时候,我们就像深海里迷失的小船一样,不知道该何去何从,又怕被风浪打翻,袭来的一切感受,都是万般皆苦,也只能是自己默默承受。</span>
</div>
<div class="_3hMwG _2kCxD ">
<div class="_1NCGf"><img
src="https://pics4.baidu.com/feed/5366d0160924ab180d0e2b7e4df528c87b890b70.jpeg@f_auto?token=14c33a6d6c74b9ecd5d123ff86da1938&amp;s=3B22C604B3E3CB744E98346D030060F9"
width="639" class="_1g4Ex _1i_Oe"></div>
</div>
<div class="dpu8C _2kCxD "><span class="bjh-p"><span class="bjh-strong">人生一世,万般皆苦,都是命,苦乐自渡,只有靠自己,才靠得住。</span></span>
</div>
<div class="dpu8C _2kCxD "><span class="bjh-p">再难的人生,也要一步一步好好走完;再苦的生活,也能咬咬牙,踮起脚,挺挺胸自己扛下。</span></div>
<div class="dpu8C _2kCxD "><span class="bjh-p">人生的路,靠自己走,才能走的踏实,走的安心,靠自己过的人生,得失无悔,苦乐自渡,不管生活如何,结局怎样,都能够笑的漂亮。</span>
</div>
</body>

</html>
"""

clipboard.copy_html(html)

print(clipboard.paste_html())

https://superuser.com/questions/912712/how-to-send-rich-text-to-the-clipboard-from-command-line

pbpaste

To extract html content from the clipboard, plain pbpaste can be used:

1
pbpaste -Prefer public.html

platform

Linux

via this answer

1
cat text.html | xclip -t text/html

Mac

via this answer

1
cat text.html | textutil -stdin -format html -convert rtf -stdout | pbcopy

Windows

In older Windows, you can natively only copy plaintext (via this answer).

1
type text.html | clip

In PowerShell you can copy rich text:

1
type text.html | Set-Clipboard -AsHtml