Search code examples
pythonpython-3.xurlbeautifulsoupurllib

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. 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.


Solution

  • Try the 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. Installation:

    pip install pyperclip