简体   繁体   English

如何使用 Python 将 URL 中的所有文本复制到剪贴板?

[英]How to copy all text from an URL to the clipboard using Python?

I want to make a script that copies all the text from an URL to the clipboard.我想制作一个脚本,将 URL 中的所有文本复制到剪贴板。 I have tried to find a solution here, and on other forums, but I have not found anything that answers the question.我试图在这里和其他论坛上找到解决方案,但我没有找到任何可以回答这个问题的东西。 I am pretty new to Python, so its hard to figure out by myself.我对 Python 很陌生,所以我自己很难弄清楚。

Try the package Pyperclip .试试 package Pyperclip Here's an example from their site这是他们网站上的一个例子

import pyperclip
pyperclip.copy('The text to be copied to the clipboard.')
spam = pyperclip.paste()

If you have a variable that stores the URL you can sub that in for the argument in copy.如果您有一个存储 URL 的变量,您可以将其用于副本中的参数。 Installation:安装:

pip install pyperclip

clipboard is cross platform (Linux, Mac & Windows), ie:剪贴板是跨平台的(Linux、Mac 和 Windows),即:

Install:安装:

pip install clipboard

Usage:用法:

import clipboard
clipboard.copy("abc")  # put "abc" on clipboard
cb_text = clipboard.paste()  # get clipboard content

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM