Pyinstaller打包Scrapy项目的实现步骤

时间:2021-05-22

1.安装pyinstaller

2.安装pywin32

3.安装其他模块

注意点:

scrapy用pyinstaller打包不能用

cmdline.execute('scrapy crawl douban -o test.csv --nolog'.split())

我用的是CrawlerProcess方式来输出

举个栗子:

1、在scrapy项目根目录下建一个crawl.py(你可以自己定义)如下图

cralw.py代码如下

# -*- coding: utf-8 -*-from scrapy.crawler import CrawlerProcessfrom scrapy.utils.project import get_project_settingsfrom douban.spiders.douban_spider import Douban_spider#打包需要的importimport urllib.robotparserimport scrapy.spiderloaderimport scrapy.statscollectorsimport scrapy.logformatterimport scrapy.dupefiltersimport scrapy.squeuesimport scrapy.extensions.spiderstateimport scrapy.extensions.corestatsimport scrapy.extensions.telnetimport scrapy.extensions.logstatsimport scrapy.extensions.memusageimport scrapy.extensions.memdebugimport scrapy.extensions.feedexportimport scrapy.extensions.closespiderimport scrapy.extensions.debugimport scrapy.extensions.httpcacheimport scrapy.extensions.statsmailerimport scrapy.extensions.throttleimport scrapy.core.schedulerimport scrapy.core.engineimport scrapy.core.scraperimport scrapy.core.spidermwimport scrapy.core.downloaderimport scrapy.downloadermiddlewares.statsimport scrapy.downloadermiddlewares.httpcacheimport scrapy.downloadermiddlewares.cookiesimport scrapy.downloadermiddlewares.useragentimport scrapy.downloadermiddlewares.httpproxyimport scrapy.downloadermiddlewares.ajaxcrawlimport scrapy.downloadermiddlewares.chunkedimport scrapy.downloadermiddlewares.decompressionimport scrapy.downloadermiddlewares.defaultheadersimport scrapy.downloadermiddlewares.downloadtimeoutimport scrapy.downloadermiddlewares.httpauthimport scrapy.downloadermiddlewares.httpcompressionimport scrapy.downloadermiddlewares.redirectimport scrapy.downloadermiddlewares.retryimport scrapy.downloadermiddlewares.robotstxtimport scrapy.spidermiddlewares.depthimport scrapy.spidermiddlewares.httperrorimport scrapy.spidermiddlewares.offsiteimport scrapy.spidermiddlewares.refererimport scrapy.spidermiddlewares.urllengthimport scrapy.pipelinesimport scrapy.core.downloader.handlers.httpimport scrapy.core.downloader.contextfactoryfrom douban.pipelines import DoubanPipelinefrom douban.items import DoubanItemimport douban.settingsif __name__ == '__main__': setting = get_project_settings() process = CrawlerProcess(settings=setting) process.crawl(Douban_spider) process.start()

2、在crawl.py目录下pyinstaller crawl.py生成dist,build(可删)和crawl.spec(可删)。

3、在crawl.exe目录下创建文件夹scrapy,然后到自己安装的scrapy文件夹中把VERSION和mime.types两个文件复制到刚才创建的scrapy文件夹中。

4、发布程序 包括douban/dist 和douban/scrapy.cfg

如果没有scrapy.cfg无法读取settings.py和pipelines.py的配置

5、在另外一台机器上测试成功

6、对于自定义的pipelines和settings,貌似用pyinstaller打包后的 exe无法读取到settings和pipelines,哪位高手看看能解决这个问题???

到此这篇关于Pyinstaller打包Scrapy项目的实现步骤的文章就介绍到这了,更多相关Pyinstaller打包Scrapy内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章