2013-06-27 90 views
2

因此,我得到了一個簡單的運行腳本,它將使用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運行腳本專門從開始菜單和管理員權限打開,但仍然得到相同的錯誤。

+0

你能提供一個完整的追溯? – alecxe

+0

如果將runner.py腳本放入「C:\ Users \ Kasutaja \ Desktop \ scrapyTest」並從那裏運行,會發生什麼? – Talvalin

+0

腳本就在那裏,因爲當我從cmd行調用scrapy crawl spider1命令時,它也可以工作。只是不通過調用runner.py – fusi0n

回答

0

從文檔

If cwd is not None, the child’s current directory will be changed to cwd before it is executed. Note that this directory is not considered when searching the executable, so you can’t specify the program’s path relative to cwd.(Emphasis mine)

對我來說,意味着你必須做一些像

Popen(["C:\Users\Kasutaja\Desktop\scrapyTest\scrapy", "crawl", "spider1"]) 

這將執行程序scrapy帶參數crawlspider1

+0

謝謝,但現在我得到Windows錯誤[5]:訪問被拒絕 – fusi0n

相關問題