问题
用阿里云运行scrapy爬虫时,当关闭了putty连接以后发现运行的爬虫进程也关闭了,不可能一直连接着putty让爬虫进行,因此通过其他的方法来实现后台运行爬虫
解决办法
- 写一个python的程序run.py,里面有运行scrapy 的代码
import os if __name__ == '__main__': os.system("scrapy crawl yourspidername")
- 通过nohup命令
nohup python -u run.py > job.log 2>1& &
这样原本格式化输出的内容都输出到job.log中了
知识点
1.os.system(command) 在子shell中执行command(字符串)命令。在windows中返回值始终为0.在UNIX中返回值表示为进程的退出状态。
Execute the command (a string) in a subshell. This is implemented by calling the Standard C function system()
, and has the same limitations. Changes to