从Python脚本调用autoit脚本



我有一个python脚本,它使用selenium转到网页的底部www.tradingview.com/screener。一旦它到达页面底部,我需要使用我制作的auto-it脚本来点击保存按钮。python脚本和auto-it脚本都是单独工作的,但我试图从python脚本中调用auto-it。我认为这可能很简单,只需在python脚本中放一行include就可以调用auto-it脚本,但它不起作用。有人知道如何做到这一点吗?我将把两个脚本都放在下面。感谢

Python Script,以转到网页底部

from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException

url = 'http://www.tradingview.com/screener'
driver = webdriver.Firefox()
driver.get(url)
try:
selector = '.js-field-total.tv-screener-table__field-value--total'
condition = EC.visibility_of_element_located((By.CSS_SELECTOR, selector))
matches = WebDriverWait(driver, 10).until(condition)
matches = int(matches.text.split()[0])
except (TimeoutException, Exception):
print ('Problem finding matches, setting default...')
matches = 4895 # Set default
# The page loads 150 rows at a time; divide matches by
# 150 to determine the number of times we need to scroll;
# add 5 extra scrolls just to be sure
num_loops = int(matches / 150 + 5)
for _ in range(num_loops):
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
sleep(1) # Pause briefly to allow loading time

单击保存按钮的Auto It脚本

; Script Start - Add your code below here
ShellExecute("https://www.tradingview.com/screener")
#include <Vince.au3>
Sleep(4000)
Send("{END 20}") ; Presses the DEL key 4 times
MouseClick($MOUSE_CLICK_LEFT, 2460, 46, 1)
Sleep(7000)
Send("{ENTER}") ; Presses the DEL key 4 times

我通常用启动AutoIT脚本

subprocess.Popen(<path to AutoIT .exe file>)

不要忘记import subprocess

最新更新