Save copy from selenium to mouse

Asked 2 years ago, Updated 2 years ago, 43 views

I entered a specific site with selenium and pressed copy to the right mouse

I wanted to save this in a txt file, so I tried many ways, but it didn't work, so I'm looking for help.


driver.close()# Right-click on selenium from the source omitted above, press copy, and drag

now = datetime.datetime.now()

filename = 'C:\py\\'

filename2 = datetime.datetime.now().strftime("%y%m%d_%H%M%S")

filename3 = '.txt'

fn = filename+filename2+filename3 

d=open(fn,'w') 

d.close() #Create a txt file with the current time as its name wherever you want

Time.sleep(1) # I want to open and paste the notepad file

os.system(fn)# Notepad runs until it opens 

time.sleep(1)    

#It won't run from below

pyautogui.MoveTo (1000, 700, 1) #Click the middle on the open screen of the notepad

time.sleep(1)

pyautogui.click()

time.sleep(1)

pyautogui.I tried typing keyDown('ctrl') #pyautogui.hotkey but it didn't work, so I tried typing the key one by one, but it didn't work

time.sleep(1)

pyautogui.press('v')

time.sleep(1)

pyautogui.keyUp('ctrl')

time.sleep(1)

pyautogui.keyDown('ctrl')

time.sleep(1)

pyautogui.press('s')

time.sleep(1)

pyautogui.keyUp('ctrl')

print('\n\t Save Complete! ')'''

If I paste it myself with a mouse or keyboard, the copy is good, but I can't paste it Is there a solution to this, or is there a better way to open it with selenium and store it in txt? (For copied information, press f12 on a specific site, right-click one of the things on the network, and click copy response.)

python selenium

2022-09-22 18:04

1 Answers

The clipboard is a system area, so you have to handle the api of the os. And it's dependent on the os. The code below is window-only and is an example of importing data from the clipboard into a Python variable.

You can save the rest of the text that you receive as a Python variable to a file.

https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getclipboarddata

import ctypes
import ctypes.wintypes as w

user32 = ctypes.windll.user32

GetClipboardData = user32.GetClipboardData
GetClipboardData.argtypes = w.UINT,
GetClipboardData.restype = w.HANDLE

user32.OpenClipboard(None)
h = GetClipboardData(13)
text = ctypes.c_wchar_p(h).value
user32.CloseClipboard()

print(text)
import win32clipboard

win32clipboard.OpenClipboard()
s = win32clipboard.GetClipboardData(13)
win32clipboard.CloseClipboard()
print(s)


2022-09-22 18:04

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.