Search code examples
htmlpython-3.xclipboard

How to copy HTML code to clipboard using Python?


I'm trying to make a simple script that copies a custom text hyperlink (< a href="FakeSite.com">Example< /a>) to the clipboard using python on Windows 10 and still have it recognized as HTML when pasted, similar to how if you copy a custom text hyperlink in Microsoft Word.

I have tried the answers given in this response but to no avail, and I have also tried a package called jaraco.clipboard but it has also proven useless. Any help or direction would be appreciated.


Solution

  • You can do this using win32clipboard via the example listed here. It requires a little customisation setting the encoding to UTF-8 (as explained in the comments) but the end result in the clipboard will contain html like properties.