What is the best way to select a text and how to store it in a variable?

Asked

Viewed 89 times

-1

I need to copy a text and I’m using the autopygui. I would like to know how best to select the text and how to store this information in a variable?

The solution I have found so far for the first problem was to tighten the shift and click on the end point of the text. For the second, I am still learning.

Follows the code.

import pyautogui

pyautogui.leftClick(1218,1051)
pyautogui.keyDown('shift')
pyautogui.leftClick(82,68)
pyautogui.keyUp('shift')
  • See the hotkey. Something like: pyautogui.hotkey('ctrl', 'c') to copy and pyautogui.hotkey('ctrl', 'v') to glue.

  • As it has not been said where you are trying to get the text from, I will give a safer suggestion if it is web page. Make the Web Scraping, is a healthier and safer way for your application. If you can give us more information, I can try to help otherwise.

2 answers

0

If that text is in a kind of textbox, where the cursor looks like the Roman number 1, you can click in this area and use the CTRL+A (select all), then copy with the CTRL+C.

0

Good how you can already copy the text, da para usar a biblioteca clipboard along with the PyAutoGui to perform the function.

Can be used like this:

import clipboard
import pyautogui

pyautogui.doubleClick(x, y) # ou na sua solução pressionar shift e clicar
pyautogui.hotkey('ctrl', 'c')
texto = clipboard.paste()
clipboard.copy("") # caso queira deixar vazia após settar a variavel.
print(text)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.