在过去的几天里,我一直在尝试将pdf的扁平化过程自动化,我发现这个函数是最有效的。唯一的问题是没有读取a.kill()命令,导致浏览器在函数完成后保持打开状态。保存过程完成后,如何关闭浏览器窗口?
import time
import subprocess
import keyboard
def chrome():
test = "test"
name = "file:///C://Users//akcgo//Documents//CARB//ARBER//PDFS//Company A.pdf"
a = subprocess.Popen("C://Program Files (x86)//Google//Chrome//Application//chrome.exe")
time.sleep(1)
keyboard.write(name)
time.sleep(1)
keyboard.press_and_release('enter')
time.sleep(1)
keyboard.press_and_release(['ctrl', 'p'])
time.sleep(1)
keyboard.press_and_release('enter')
time.sleep(1)
keyboard.write(test)
time.sleep(.5)
keyboard.press_and_release('enter')
time.sleep(2)
a.kill()
# keyboard.press_and_release(['ctrl', 'w']) doesn't work either
1条答案
按热度按时间lymgl2op1#
您可以使用
pid = a.pid
,然后打电话os.kill(pid, signal.SIGTERM)
或os.kill(pid, signal.SIGKILL)
.