2013-10-18 51 views
5

我使用scrapy創建一個項目並在「spider」文件夾中添加我自己的蜘蛛,稱爲「spider_us.py」,並且我想構建一個可以在其他計算機上執行的exe文件,而無需安裝scrapy。如何使用py2exe構建我的scrapy蜘蛛到exe文件?

當我跟隨py2exe的指示,我做在同一個文件夾中的新文件「Setup.py」具有以下內容:

from distutils.core import setup 
import py2exe 

setup(console = ["spider_us.py"]) 

然而,它沒有工作,因爲我跑的時候我蜘蛛,我使用命令「scrapy crawl spider_us」而不是直接運行「spider」文件夾中的文件「spider_us.py」。

怎麼可能建立在整個蜘蛛程序(在我的情況「spider_us.py」),以一個exe文件,不僅蜘蛛文件(當我使用「scrapy startproject命令XXX」由scrapy自動創建) 「蜘蛛」子文件夾。

任何人都提供一些建議或幫助,歡迎任何評論。非常感謝。

回答

1

嘗試通過Python腳本運行蜘蛛(而不是命令scrapy crawl <spider_name>)。你需要編寫一些代碼,例如:

from twisted.internet import reactor 
from scrapy.crawler import Crawler 
from scrapy import log, signals 
from testspiders.spiders.followall import FollowAllSpider 
from scrapy.utils.project import get_project_settings 

spider = FollowAllSpider(domain='scrapinghub.com') 
settings = get_project_settings() 
crawler = Crawler(settings) 
crawler.signals.connect(reactor.stop, signal=signals.spider_closed) 
crawler.configure() 
crawler.crawl(spider) 
crawler.start() 
log.start() 
reactor.run() # the script will block here until the spider_closed signal was sent 

有關詳細信息,請參閱the documentations on "Run Scrapy from a script"