请求html源文档 get,从X剪贴板获取HTML源或富文本

该博客介绍了如何利用Python和GTK库来与X11剪贴板进行交互,通过查询并尝试不同的数据格式来获取剪贴板中的内容。示例代码展示了如何等待并打印出可用的目标及对应的内容,特别是对HTML和字符串格式的数据进行了尝试。
摘要由CSDN通过智能技术生成

在X11中,您必须与选择所有者通信,询问支持的格式,然后以特定格式请求数据。我认为最简单的方法是使用现有的窗口工具包。例如。与Python和GTK:

#!/usr/bin/python

import glib,gtk

def test_clipboard():

clipboard = gtk.Clipboard()

targets = clipboard.wait_for_targets()

print "Targets available:",",".join(map(str,targets))

for target in targets:

print "Trying '%s'..." % str(target)

contents = clipboard.wait_for_contents(target)

if contents:

print contents.data

def main():

mainloop = glib.MainLoop()

def cb():

test_clipboard()

mainloop.quit()

glib.idle_add(cb)

mainloop.run()

if __name__ == "__main__":

main()

输出将如下所示:

$ ./clipboard.py

Targets available: TIMESTAMP,TARGETS,MULTIPLE,text/html,text/_moz_htmlcontext,text/_moz_htmlinfo,UTF8_STRING,COMPOUND_TEXT,TEXT,STRING,text/x-moz-url-priv

...

Trying 'text/html'...

I asked the same question on superuser.com,because I was hoping there was a utility to do this,but I didn't get any informative responses.

Trying 'text/_moz_htmlcontext'...

...

Trying 'STRING'...

I asked the same question on superuser.com,but I didn't get any informative responses.

Trying 'text/x-moz-url-priv'...

http://stackoverflow.com/questions/3261379/getting-html-source-or-rich-text-from-the-x-clipboard

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值