Python获取选定的文本 [英] Python get selected text

查看:101
本文介绍了Python获取选定的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将如何使用用户在Web浏览器中选择的Python捕获"文本?该脚本将在后台闲置,并且当按下某个组合键时,它将获取"用户选择的文本.认为复制和粘贴,仅复制到我的应用程序而不是剪贴板.

How would I, using Python "catch" text that a user has selecting in, for example, a web browser? The script would idle in the background, and when a certain key combination is pressed, it "gets" the text the user has selected. Think copy & paste, only it copies to my application instead of a clipboard.

谢谢!我想指出的是,这将适用于Mac.

Thanks! I'd like to point out that this will be for Mac.

推荐答案

  1. 安装xsel

sudo apt-get install xclip xsel -y

  • 另存为get-selected.py

    import os
    print(os.popen('xsel').read())
    

  • 选择文本

  • Select text

    运行

    python get-selected.py
    

  • 这篇关于Python获取选定的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆