如何将Scrapy脚本打包成独立应用程序?

3

我有一组Scrapy爬虫。它们需要每天从桌面应用程序运行。 对于用户来说,安装和在另一台Windows机器上运行它的最简单方法是什么?

3个回答

1
创建一个脚本(例如 run_spider.py)作为系统命令运行 scrapy crawl <spider_name>

run_spider.py

from os import system
output_file_name = 'results.csv'
system('scrapy crawl myspider -o ' + output_file_name + ' -t csv')

然后将该脚本提供给PyInstaller:
pyinstaller run_spider.py

0

最简单的方法是为他们编写一个Python脚本,我想...

如果您正在运行Windows服务器,甚至可以安排使用的命令(scrapy crawl yoursprider)来运行蜘蛛。


0

这里有另一种可能性,可以将您的爬虫作为独立脚本或可执行文件运行

import scrapy
from scrapy.crawler import CrawlerProcess

class MySpider(scrapy.Spider):
    # Your spider definition
    ...

process = CrawlerProcess({
    'USER_AGENT': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)'
})

process.crawl(MySpider)
process.start() # the script will block here until the crawling is finished

您可以在这里找到更多信息:https://doc.scrapy.org/en/1.0/topics/practices.html


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接