如何将网站上的文本转换为变量?

How can I get a text on a website into a variable?

使用 PyAutoGui,我正在自动化我的工作流程。在网站上,我在非常具体的 (x, y) 坐标处有一个整数。是否可以将整数值传输到变量中以便我可以用它做数学运算?

我已经尝试复制输入并将其输入到输入框中,但脚本总是在我可以使用打字机之前等待输入。

pyautogui.typewrite("\n")
pyautogui.moveTo(1850, 430, duration=5)
pyautogui.click()
#Now the Integer is marked; Can I get it stored in a variable?

我希望整数存储在变量中(例如"amount.")

pyperclip 是一个非常有用的 copy/paste 模块,即使您只使用 pyperclip.paste()。因此,要添加到您的代码中:

import pyperclip

# first we use pyautogui to copy the text we highlighted to the clipboard
pyautogui.hotkey('ctrl', 'c')

#now we use pyperclip.paste(), which sends the clipboard text to a variable
#also we need to cast the string to an int
try:
    amount = int(pyperclip.paste())
    #just checking we got what we need
    print(amount, type(amount))
except:
    print("Oh no. We didn't highlight an integer value.")