本文整理匯總了Python中scrapy.http.request.Request.meta['file_name']方法的典型用法代碼示例。如果您正苦於以下問題:Python Request.meta['file_name']方法的具體用法?Python Request.meta['file_name']怎麽用?Python Request.meta['file_name']使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類scrapy.http.request.Request
的用法示例。
在下文中一共展示了Request.meta['file_name']方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: parse_article
# 需要導入模塊: from scrapy.http.request import Request [as 別名]
# 或者: from scrapy.http.request.Request import meta['file_name'] [as 別名]
def parse_article(self, response):
title = response.meta['title']
date = response.meta['date']
file_name = '/root/sixminuteenglish/%s %s' % (date, title)
sel = Selector(response)
audio_links = sel.css('a.audio-link::attr("href")').extract()
script_links = sel.css('a.pdf-link::attr("href")').extract()
if len(audio_links) > 0 and len(script_links) > 0:
req1 = Request(audio_links[0], callback=self.download_file)
req1.meta['file_name'] = file_name + '.mp3'
req2 = Request(script_links[0], callback=self.download_file)
req2.meta['file_name'] = file_name + '.pdf'
return req1, req2
示例2: parse_article
# 需要導入模塊: from scrapy.http.request import Request [as 別名]
# 或者: from scrapy.http.request.Request import meta['file_name'] [as 別名]
def parse_article(self, response):
title = response.meta['title']
date = response.meta['date']
file_name = '/root/listentoenglish/%s %s' % (date, title)
sel = Selector(response)
audio_links = sel.xpath('//a[contains(text(), "Download MP3")]/@href').extract()
scripts = sel.css('div.entry div.clearfloats p::text').extract()
if len(audio_links) > 0 and len(scripts) > 0:
script = ''.join(scripts).encode('UTF-8')
with open(file_name + '.txt', 'w') as f:
f.write(script)
req = Request(audio_links[0], callback=self.download_file)
req.meta['file_name'] = file_name + '.mp3'
return req