728x90
λ°μν
example.py
import time
import klembord
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
options = Options()
options.add_argument("--headless")
options.add_argument("--disable-gpu")
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
driver = webdriver.Chrome(options=options)
driver.get("https://example.com/")
time.sleep(2)
element = driver.find_element("xpath", "/html/body/div")
html = element.get_attribute("innerHTML")
# Copy using klembord to keep the formatting
# element.text is plain text and text is html
klembord.set_with_rich_text(element.text, html)
driver.quit()
μΆμ²:
https://stackoverflow.com/questions/75592229/how-to-copy-text-with-formatting-using-python-selenium
How to copy text with formatting using Python + Selenium?
I'm using Python and Selenium and I need to copy text from a webpage to the OS Windows clipboard with formatting. For example, when you copy text from a webpage by pressing the Ctrl+C key combinati...
stackoverflow.com
saveClipboard.py - ν΄λ¦½λ³΄λ κ°μ Έμμ νμΌλ‘ μ μ₯νκΈ°
import klembord
f = open('clipboard1.txt', 'w', encoding='utf-8') # ν
μ€νΈλ§ κ°μ Έμ€κΈ°
f.write( klembord.get_with_rich_text()[0] )
f.close()
f = open('clipboard2.txt', 'w', encoding='utf-8') # ν
μ€νΈ νμ κ°μ Έμ€κΈ°
f.write( klembord.get_with_rich_text()[1] )
f.close()
728x90
λ°μν