【发布时间】:2018-02-03 20:05:31
【问题描述】:
我有一个 Flask 网络应用程序以这种方式运行爬取过程:
在终端标签 1 上:
$ cd /path/to/scraping
$ scrapyrt
在终端标签 2 上:
$ python app.pp
在app.py:
params = {
'spider_name': spider,
'start_requests':True
}
response = requests.get('http://localhost:9080/crawl.json', params)
print ('RESPONSE',response)
data = json.loads(response.text)
哪个有效。
现在我想将所有内容移至app.py,为此我已经尝试过:
import subprocess
from time import sleep
try:
subprocess.check_output("scrapyrt", shell=True, cwd='path/to/scraping')
except subprocess.CalledProcessError as e:
raise RuntimeError("command '{}' return with error (code {}): {}".format(e.cmd, e.returncode, e.output))
sleep(3)
params = {
'spider_name': spider,
'start_requests':True
}
response = requests.get('http://localhost:9080/crawl.json', params)
print ('RESPONSE',response)
data = json.loads(response.text)
这开始扭曲,像这样:
2018-02-03 17:29:35-0200 [-] Log opened.
2018-02-03 17:29:35-0200 [-] Site starting on 9080
2018-02-03 17:29:35-0200 [-] Starting factory <twisted.web.server.Site instance at 0x104effa70>
但是爬取过程挂起并且没有通过。
我在这里错过了什么?
【问题讨论】:
标签: flask scrapy subprocess