所以我得到了一个简单的运行脚本,它将使用 Popen 来调用蜘蛛。运行器脚本如下:
from subprocess import Popen
import time
def runSpider():
p = Popen(["scrapy", "crawl", "spider1"],
cwd="C:\Users\Kasutaja\Desktop\scrapyTest")
stdout, stderr = p.communicate()
time.sleep(15)
runSpider()
目录是这样的:
-----scrapyTest:
--------------------scrapyTest[folder]: spider[folder], items.py, pipelines.py, settings.py
--------------------runner.py
--------------------scrapy.cfg
当我从 cmd 行运行它时,蜘蛛从目录中完美运行:C:\Users\Kasutaja\Desktop\scrapyTest 。
当我运行我的 runner.py 脚本时,我得到:
该系统找不到指定的文件
编辑:
将 Popen 更改为此后:
p = Popen(["C:\Users\Kasutaja\Desktop\scrapyTest","scrapy", "crawl", "spider1"])
我得到错误:
C:\Users\Kasutaja\Desktop\scrapyTest>python runner.py
Traceback (most recent call last):
File "runner.py", line 13, in <module>
runSpider()
File "runner.py", line 8, in runSpider
p = Popen(["C:\Users\Kasutaja\Desktop\scrapyTest","scrapy", "crawl", "spider
1"])
File "C:\Python27\lib\subprocess.py", line 679, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 896, in _execute_child
startupinfo)
WindowsError: [Error 5] Access is denied
如果重要的话,我有管理员权限。我现在也尝试过,使用从开始菜单和管理员权限专门打开的 cmd 运行脚本,但仍然得到相同的错误。