Scrapyd Spider.의 Jobid 값
문제
프레임 워크 스크랩 - scrapyd 서버.
스파이더 안에 Jobid 값을 얻는 데 문제가 있습니다. http : // localhost : 6800 / schedule.json 응답이
status = ok
jobid = bc2096406b3011e1a2d0005056c00008
.
그러나 프로세스 중에 현재 거미 내부 에서이 jobid를 사용할 필요가 있습니다.열린 {JobID} .log 파일 또는 기타 동적 이유로 사용할 수 있습니다.
class SomeSpider(BaseSpider):
name = "some"
start_urls = ["http://www.example.com/"]
def parse(self, response):
items = []
for val in values:
item = SomeItem()
item['jobid'] = self.jobid # ???!
items.append(item)
return items
.
하지만이 작업이 finihed 이후에만이 지향적 인 것을 본다 :( 감사합니다!
해결책
I guess there is an easier way, but you can extract job id from command line args. IIRC, scrapyd launches a spider giving it a jobid in parameters. Just explore sys.args
where you need jobid.
다른 팁
You can get it from the SCRAPY_JOB
environment variable:
os.environ['SCRAPY_JOB']
제휴하지 않습니다 StackOverflow