本文整理汇总了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