本文整理汇总了Python中scrapy.http.request.Request.meta['name']方法的典型用法代码示例。如果您正苦于以下问题:Python Request.meta['name']方法的具体用法?Python Request.meta['name']怎么用?Python Request.meta['name']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scrapy.http.request.Request
的用法示例。
在下文中一共展示了Request.meta['name']方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_solutions
# 需要导入模块: from scrapy.http.request import Request [as 别名]
# 或者: from scrapy.http.request.Request import meta['name'] [as 别名]
def parse_solutions(self,response):
hxs = HtmlXPathSelector(response)
x = hxs.select("//tr[@class='kol']//td[8]/ul/li/a/@href").extract()
filename = response.meta['name']
for i in range(10):
request = Request('http://www.codechef.com/viewplaintext/'+x[i].split('/')[-1], callback=self.parse_ptsol)
request.meta['name'] = filename
request.meta['count'] = str(i)
yield request
示例2: parse_item
# 需要导入模块: from scrapy.http.request import Request [as 别名]
# 或者: from scrapy.http.request.Request import meta['name'] [as 别名]
def parse_item(self, response):
hxs = HtmlXPathSelector(response)
item = Problem()
item['title'] = hxs.select("//table[@class='pagetitle-prob']/tr/td/h1/text()").extract()
item['content'] = hxs.select("//div[@class='node clear-block']//div[@class='content']").extract()
filename = str(item['title'][0])
solutions_url = 'http://www.codechef.com/status/' + response.url.split('/')[-1] + '?language=All&status=15&handle=&sort_by=Time&sorting_order=asc'
request = Request(solutions_url, callback=self.parse_solutions)
request.meta['name'] = filename
yield request
if not os.path.exists('problems'): os.makedirs('problems')
if not os.path.exists('problems/'+filename): os.makedirs('problems/'+filename)
f = open('problems/' + filename+'/question.html','wb')
f.write('<head>')
f.write('<meta charset="UTF-8">')
f.write('</head>')
f.write("<div style='width:800px;margin:50px'>")
for i in item['content']:
f.write(i.encode("utf-8"))
f.write("</div>")
f.close()