popen.kill不关闭浏览器窗口

iq0todco  于 2021-09-29  发布在  Java
关注(0)|答案(1)|浏览(347)

在过去的几天里,我一直在尝试将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
lymgl2op

lymgl2op1#

您可以使用 pid = a.pid ,然后打电话 os.kill(pid, signal.SIGTERM)os.kill(pid, signal.SIGKILL) .

相关问题