因此,我得到了一個簡單的運行腳本,它將使用Popen來調用蜘蛛。 亞軍腳本如下:Windows無法在目錄中找到scrapy文件
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
蜘蛛完全從目錄中運行:C:\用戶\ Kasutaja \桌面\ scrapyTest當我從cmd行運行它。
當我跑我的runner.py腳本,我得到:
The system cannot find the file specified
編輯:
改變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運行腳本專門從開始菜單和管理員權限打開,但仍然得到相同的錯誤。
你能提供一個完整的追溯? – alecxe
如果將runner.py腳本放入「C:\ Users \ Kasutaja \ Desktop \ scrapyTest」並從那裏運行,會發生什麼? – Talvalin
腳本就在那裏,因爲當我從cmd行調用scrapy crawl spider1命令時,它也可以工作。只是不通過調用runner.py – fusi0n