【发布时间】:2013-09-03 03:57:27
【问题描述】:
我有一套 Scrapy 蜘蛛。它们需要每天从桌面应用程序运行。 在另一台 Windows 机器上安装和运行它的最简单方法是什么(从用户的角度来看)?
【问题讨论】:
标签: python scrapy desktop-application py2exe pyinstaller
我有一套 Scrapy 蜘蛛。它们需要每天从桌面应用程序运行。 在另一台 Windows 机器上安装和运行它的最简单方法是什么(从用户的角度来看)?
【问题讨论】:
标签: python scrapy desktop-application py2exe pyinstaller
创建一个将scrapy crawl <spider_name> 作为系统命令运行的脚本(例如run_spider.py)。
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
【讨论】:
我猜最简单的方法是用python为他们编写一个脚本......
如果您运行的是 Windows Server,您甚至可以安排您使用的命令(scrapy crawl yoursprider)来运行蜘蛛。
【讨论】:
这是另一种将蜘蛛作为独立脚本或可执行文件运行的可能性
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
【讨论】: