input/output 对于托管在 Amazon EC2 linux 实例上的 scrapyd 实例
input/output for scrapyd instance hosted on an Amazon EC2 linux instance
最近我开始使用 scrapy 构建网络抓取工具。最初我是使用scrapyd在本地部署我的scrapy项目。
我构建的 scrapy 项目依赖于从 CSV 文件访问数据,以便 运行
def search(self, response):
with open('data.csv', 'rb') as fin:
reader = csv.reader(fin)
for row in reader:
subscriberID = row[0]
newEffDate = datetime.datetime.now()
counter = 0
yield scrapy.Request(
url = "https://www.healthnet.com/portal/provider/protected/patient/results.action?__checkbox_viewCCDocs=true&subscriberId=" + subscriberID + "&formulary=formulary",
callback = self.find_term,
meta = {
'ID': subscriberID,
'newDate': newEffDate,
'counter' : counter
}
)
它将抓取的数据输出到另一个 CSV 文件
for x in data:
with open('missing.csv', 'ab') as fout:
csvwriter = csv.writer(fout, delimiter = ',')
csvwriter.writerow([oldEffDate.strftime("%m/%d/%Y"),subscriberID,ipa])
return
我们正处于构建需要访问和 运行 这些 scrapy 蜘蛛的应用程序的初始阶段。我决定在 AWS EC2 linux 实例上托管我的 scrapyd 实例。部署到 AWS 非常简单 (http://bgrva.github.io/blog/2014/04/13/deploy-crawler-to-ec2-with-scrapyd/)。
如何在 AWS EC2 linux 实例上 input/output 抓取数据 to/from scrapyd 实例 运行ning?
编辑:
我假设传递一个文件看起来像
curl http://my-ec2.amazonaws.com:6800/schedule.json -d project=projectX -d spider=spider2b -d in=file_path
这是正确的吗?我将如何获取此蜘蛛 运行 的输出?这种方法有安全问题吗?
S3 是一个选项吗?我问是因为您已经在使用 EC2。如果是这样的话,你可以 read/write from/to S3.
我有点困惑,因为您同时提到了 CSV 和 JSON 格式。如果您正在阅读 CSV,您可以使用 CSVFeedSpider. Either way, you could also use boto 在蜘蛛的 __init__
或 start_requests
方法中从 S3 读取。
关于输出,this page 解释了如何使用提要导出将抓取的输出写入 S3。
相关设置:
最近我开始使用 scrapy 构建网络抓取工具。最初我是使用scrapyd在本地部署我的scrapy项目。
我构建的 scrapy 项目依赖于从 CSV 文件访问数据,以便 运行
def search(self, response):
with open('data.csv', 'rb') as fin:
reader = csv.reader(fin)
for row in reader:
subscriberID = row[0]
newEffDate = datetime.datetime.now()
counter = 0
yield scrapy.Request(
url = "https://www.healthnet.com/portal/provider/protected/patient/results.action?__checkbox_viewCCDocs=true&subscriberId=" + subscriberID + "&formulary=formulary",
callback = self.find_term,
meta = {
'ID': subscriberID,
'newDate': newEffDate,
'counter' : counter
}
)
它将抓取的数据输出到另一个 CSV 文件
for x in data:
with open('missing.csv', 'ab') as fout:
csvwriter = csv.writer(fout, delimiter = ',')
csvwriter.writerow([oldEffDate.strftime("%m/%d/%Y"),subscriberID,ipa])
return
我们正处于构建需要访问和 运行 这些 scrapy 蜘蛛的应用程序的初始阶段。我决定在 AWS EC2 linux 实例上托管我的 scrapyd 实例。部署到 AWS 非常简单 (http://bgrva.github.io/blog/2014/04/13/deploy-crawler-to-ec2-with-scrapyd/)。
如何在 AWS EC2 linux 实例上 input/output 抓取数据 to/from scrapyd 实例 运行ning?
编辑: 我假设传递一个文件看起来像
curl http://my-ec2.amazonaws.com:6800/schedule.json -d project=projectX -d spider=spider2b -d in=file_path
这是正确的吗?我将如何获取此蜘蛛 运行 的输出?这种方法有安全问题吗?
S3 是一个选项吗?我问是因为您已经在使用 EC2。如果是这样的话,你可以 read/write from/to S3.
我有点困惑,因为您同时提到了 CSV 和 JSON 格式。如果您正在阅读 CSV,您可以使用 CSVFeedSpider. Either way, you could also use boto 在蜘蛛的 __init__
或 start_requests
方法中从 S3 读取。
关于输出,this page 解释了如何使用提要导出将抓取的输出写入 S3。
相关设置: