(长时间的使用者&第一个问题和紧张地问)是真的吗?
我目前正在构建一个Python后端,该后端将部署到一个AWS EC2实例中,该实例具有以下体系结构:
--数据源
网络爬虫数据-保存到S3* =\
API数据管道
如上所示,我们有不同的获取数据的方法(例如API请求、等)但是,棘手的/困难的部分是想出一种简单的、容错的方法将接收到的数据与Luigi数据管道连接起来。
有没有办法将网络爬虫的输出集成到Luigi数据管道中?如果不是,如何才能最好地弥合HTTP数据获取器和Luigi任务之间的差距?
任何建议,文件,或文章将是超级感谢!另外,如果你需要更多的细节,我会尽快把它们弄进来。
谢谢!
发布于 2017-06-13 21:52:30
我从来没有用过路易吉。但我确实用刮痕。我想真正的问题是你如何合理地通知luigi有新的数据需要处理?
还有一个类似的问题,你可以从这里学到:When a new file arrives in S3, trigger luigi task,也许你们在同一个地方工作:)。
我强烈建议把你的蜘蛛放在剪贴里,用剪贴-客户端来驱动它。如果尝试在使用扭曲库的其他工具中运行scrapy (不确定luigi是否这样做),就会弹出各种各样的毛茸茸的东西。我会用剪贴客户端驱动蜘蛛,让你的蜘蛛发到一个触发url,告诉luigi以某种方式启动任务。
同样,由于我没有使用luigi,我不知道细节there...but,您不希望忙于检查/轮询,以确定工作是否已经完成。
我有一个django网络应用程序,我启动蜘蛛,存储从剪贴-客户,并得到一个json点击肩膀,然后我使用芹菜和solr摄取数据。
编辑以包含以下注释中的管道代码:
for fentry in item['files']:
# open and read the file
pdf = open(rootdir+os.path.sep+fentry['path'],'rb').read()
# just in case we need cookies
cj = CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
# set the content type
headers = {
'Content-Type': 'application/json'
}
#fill out the object
json_body = json.dumps({
'uid' : 'indeed-'+item['indeed_uid'],
'url' : item['candidate_url'],
'first_name' : fname,
'last_name' : lname,
'pdf' : base64.b64encode(pdf).decode(),
'jobid': spider.jobid
}).encode()
#, ensure_ascii=False)
# send the POST and read the result
request = urllib.request.Request('http://localhost:8080/api/someapi/', json_body, headers)
request.get_method = lambda: 'POST'
response = opener.open(request)https://stackoverflow.com/questions/44531459
复制相似问题