我使用scrapy创建一个项目,并在"spiders“文件夹中添加我自己的爬行器,比如"spider_us.py",我想构建一个可在其他计算机上执行的可执行文件,而不需要安装scrapy。
当我按照py2exe的指示操作时,我在同一个文件夹中创建了一个新文件"Setup.py“,内容如下:
from distutils.core import setup
import py2exe
setup(console = ["spider_us.py"])然而,它不起作用,因为当我运行我的爬虫时,我使用命令"scrapy crawl spider_us“,而不是直接运行”爬虫“文件夹中的文件"spider_us.py”。
如何将整个爬虫程序(当我使用"scrapy startproject XXX“时由scrapy自动创建)构建到一个exe文件中,而不仅仅是"spiders”子文件夹中的爬虫文件(在我的例子中是“spider_us.py”)。
任何人提供一些建议或帮助,任何意见都是欢迎的。非常感谢。
发布于 2014-10-24 20:13:46
尝试通过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"
https://stackoverflow.com/questions/19440392
复制相似问题