我有我要输出其结果到标准输出,以便它可以通过subprocess.check_output
读取的蜘蛛。我不想输出到文件作为中介。
我试着加入标志'-o', 'stdout'
,但它不工作。
test = subprocess.check_output([
'scrapy', 'runspider', 'spider.py',
'-a', f"keywords={keywords}", '-a', f'domain={domain}', '-a', f'page={1}',
'-s', 'USER_AGENT=Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)',
])
试试这个:主要的.py
from subprocess import Popen, PIPE
command = ["scrapy runspider yourspider.py -a some additional commands"]
proc = Popen(command, shell=True, stdout=PIPE, stderr=PIPE)
proc.wait()
res = proc.communicate()
if proc.returncode:
print(res[1])
print('result:', res[0])
子yourspider.py
import sys
# your code
print(something what you need to transfer)