python调用window程序
import os
import time
import win32api
import subprocess
path = r"C:\data\liyugeng\SpiderPro\amazon"
def runSpider():
os.getcwd()
os.chdir(path=path)
command = 'py -3 -m scrapy crawl amaz'
process_1 = subprocess.Popen(command.split())
process_2 = subprocess.Popen(command.split())
process_3 = subprocess.Popen(command.split())
process_4 = subprocess.Popen(command.split())
time.sleep(60*20) # 设置爬虫每次运行的时间
win32api.TerminateProcess(int(process_1._handle), -1)
win32api.TerminateProcess(int(process_2._handle), -1)
win32api.TerminateProcess(int(process_3._handle), -1)
win32api.TerminateProcess(int(process_4._handle), -1)
# 每次运行20分钟重启一次,循环3*24次(也就是一天的时间)
for i in range(3*24):
runSpider()