Passing a argument to a Scrapy callback function [duplicate]

This is what you’d use the meta Keyword for. def parse(self, response): for sel in response.xpath(‘//tbody/tr’): item = HeroItem() # Item assignment here url=”https://” + item[‘server’] + ‘.battle.net/’ + sel.xpath(‘td[@class=”cell-BattleTag”]//a/@href’).extract()[0].strip() yield Request(url, callback=self.parse_profile, meta={‘hero_item’: item}) def parse_profile(self, response): item = response.meta.get(‘hero_item’) item[‘weapon’] = response.xpath(‘//li[@class=”slot-mainHand”]/a[@class=”slot-link”]/@href’).extract()[0].split(“https://stackoverflow.com/”)[4] yield item Also note, doing sel = Selector(response) is a waste … Read more

pass callback from python to c++ using boost::python

Ok, I’m still trying to figure this out too, but here’s whats working for me so far: #this is the variable that will hold a reference to the python function PyObject *py_callback; #the following function will invoked from python to populate the call back reference PyObject *set_py_callback(PyObject *callable) { py_callback = callable; /* Remember new … Read more

Detecting Client Death in WCF Duplex Contracts

In his ‘Programming WCF Services’ book, Juval Lowy explains that WCF does not provide a mechansim for managing service callbacks, and this must be managed by the service and client explicitly. If the service attempts to invoke a callback which has been closed on the client, an ObjectDisposedException will be thrown on the service channel. … Read more

Jquery – Perform callback after append

jQuery’s .each() takes a callback function and applies it to each element in the jQuery object. Imagine something like this: $(‘a.ui-icon-cart’).click(function(){ $(this).closest(‘li’).clone().appendTo(‘#cart ul’).each(function() { $(this).find(‘h5’).remove(); $(this).find(‘img’).css({‘height’:’40px’, ‘width’:’40px’}); $(this).find(‘li’).css({‘height’:’60px’, ‘width’:’40px’}); }); }); You could also just store the result and work on it instead: $(‘a.ui-icon-cart’).click(function(){ var $new = $(this).closest(‘li’).clone().appendTo(‘#cart ul’) $new.find(‘h5’).remove(); $new.find(‘img’).css({‘height’:’40px’, ‘width’:’40px’}); $new.find(‘li’).css({‘height’:’60px’, ‘width’:’40px’}); }); … Read more

passing index from for loop to ajax callback function (JavaScript)

You could use a javascript closure: for (var i = 0; i < arr.length; i++) { (function(i) { // do your stuff here })(i); } Or you could just use $.each: var arr = [2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010]; $.each(arr, function(index, value) { $.ajaxSetup({ cache:false }); $.getJSON(“NatGeo.jsp”, { ZipCode: value, … Read more

understanding the concept of javascript callbacks with node.js, especially in loops

If the callback is defined in the same scope the loop is defined in (which is frequently the case), then the callback will have access to the index variable. Leaving aside NodeJS particulars for a moment, let’s consider this function: function doSomething(callback) { callback(); } That function accepts a callback function reference and all it … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)